4

I have DXF File that contains an arc.

I did the procedure to import a DXF file and generate a Graphics3D as below:

Import["C:\\Users\\Leandro\\Desktop\\Arco.dxf","Graphics3D"]
InputForm[%]

The image below is the output I get, but is not very useful for me:

output

Question: Is it possible to create a function whose output would be something like:

Graphics[{Circle[{75,129.90381057},{150,150},{4.1887902,5.23598776}]}]

Would someone have an idea of ​​how to at least use these lines to determine the center and radius?

LCarvalho
  • 9,233
  • 4
  • 40
  • 96
  • When you post a file that is on dropbox, the link you get when you choose to share it often ends in a "..dl=0", and when people open the link it takes them to a webpage where they then have to click somewhere to download the file. If you change the "0" to a "1", then the link becomes a direct link to the file. – Jason B. Aug 17 '16 at 20:28
  • I changed, but for me it appears an error. – LCarvalho Aug 17 '16 at 20:34
  • Odd, when I click it now, it downloads directly. Not that my phone knows what to do with it once downloaded.... – Jason B. Aug 17 '16 at 20:37
  • OK then. See you... – LCarvalho Aug 17 '16 at 20:41

2 Answers2

6

I couldn't download your data for some reason, so I'll use the one in Sjoerd's answer, which I assigned to myArc.

You have a number of points with inexact coordinates, so I would not rely too much on being able to compute the circumcircle. A safe method is to use the ones in this thread; the one in my answer there is quite compact:

{a, b1, b2, c} = Flatten[Last[SingularValueDecomposition[Flatten[{Norm[#]^2, #, 1}] & /@
                                                         myArc, -1]]];
{cen, rad} = {-{b1, b2}/(2 a), Sqrt[(b1^2 + b2^2)/(4 a^2) - c/a]};

Graphics[{AbsolutePointSize[5], Point[myArc], Circle[cen , rad]}]

given points and associated circle

To get just the arc itself, do this:

{θ1, θ2} = ArcTan @@@ (TranslationTransform[-cen] /@ myArc[[{1, -1}]]);
Graphics[{AbsolutePointSize[5], Point[myArc], Circle[cen , rad, {θ1, θ2}]

or this

(* https://mathematica.stackexchange.com/a/10994 *)
arc[center_?VectorQ, {start_?VectorQ, end_?VectorQ}] := Module[{ang, co, r},
    ang = VectorAngle[start - center, end - center];
    co = Cos[ang/2]; r = EuclideanDistance[center, start];
    BSplineCurve[{start, center + r/co Normalize[(start + end)/2 - center], end}, 
                 SplineDegree -> 2, SplineKnots -> {0, 0, 0, 1, 1, 1},
                 SplineWeights -> {1, co, 1}]]

Graphics[{AbsolutePointSize[5], Point[myArc], arc[cen, myArc[[{1, -1}]]]}]

Both should yield the following picture: the arc itself

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
4

Easy, if you have 10.0 or higher:

data = 
Cases[
   Import["D:\\Users\\Sjoerd\\Downloads\\Arco.dxf", "Graphics3D"], 
   Line[a___] :> a, 
   Infinity
][[1, All, {1, 2}]]

{{-7.10543*10^-14, 3.42197*10^-11}, {6.90143, -3.74717}, {13.9895, -7.12801}, {21.2448, -10.1333}, {28.6475, -12.7547}, {36.1771, -14.9851}, {43.8132, -16.8183}, {51.5348, -18.2494}, {59.3207, -19.2745}, {67.1496, -19.8906}, {75., -20.0962}, {82.8504, -19.8906}, {90.6793, -19.2745}, {98.4652, -18.2494}, {106.187, -16.8183}, {113.823, -14.9851}, {121.353, -12.7547}, {128.755, -10.1333}, {136.01, -7.12801}, {143.099, -3.74717}, {150., 3.41913*10^-11}}

{center, radius} = List @@ Circumsphere[data[[{1, Length[data]/2 // Round, -1}]]]
(* {{75., 129.904}, 150.} *)

For versions earlier than v10, have a look at my answer here.

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323