1. ## Finding arc angles

I'm writing a program to read dxf files and send them directly to my lasercutter. Most of the entities from autocad's DXF are already working but I'm having difficulties with the bulge of LWPOLYLINE and POLYLINE.

From the given start x,y, end x,y and bulge factor I can already calculate centerpoint of the circle, radius and the distance between the 2 points.

The thing I need to know is the start and end angle. Some simple trigonometry I guess but I can't get it working!

This is what it currently draws:

This is what it should be:

Does anyone have some hints what I should look for? I think the problem is near the point where x and y go negative or something..

2. Here's how I do it in AutoCAD VBA. Red and green are comments

' Find Center of Arc

If BulgeN <> 0 Then 'If Bulge is NOT zero BulgeN is the bulge

' First find chord of arc

ChordL = Sqr((RetCoord(X) - RetCoord(X - 2)) ^ 2 + (RetCoord(y) - RetCoord(y - 2)) ^ 2)

RetCoord(X)= X end of arc
RetCoord(X-2)= X start of arc
RetCoord(Y)= Y end of arc
RetCoord(Y-2)= Y start of arc

' Set Start point of Arc as pt1 and End Point as pt2

Pt1(0) = RetCoord(X - 2): Pt1(1) = RetCoord(y - 2): Pt1(2) = 0
Pt2(0) = RetCoord(X): Pt2(1) = RetCoord(y): Pt2(2) = 0

BulgeAngle = (4 * Atn(BulgeN)) * 180 / pi ' included angle

r = Abs(ChordL / (2 * Sin((4 * Atn(BulgeN)) / 2))) ' Find Radius of Arc

ReturnAngle = ThisDrawing.Utility.AngleFromXAxis(Pt1, Pt2) 'This is an AutoCAD VBA function. You'll need to use trig to get this angle

' Find angle from Start point to Center Point

AngleToCenter = ReturnAngle + (pi / 2 - (2 * Atn(BulgeN)))

' Find Center Point

CenterPt = ThisDrawing.Utility.PolarPoint(Pt1, AngleToCenter, r) Another AutoCAD VBA function = more trig for you

If GWord = "G3" Then
ILoc = CStr(FormatNumber(Round(CenterPt(0) - RetCoord(X - 2), Precision), Precision, -1, 0, 0))
JLoc = CStr(FormatNumber(Round(CenterPt(1) - RetCoord(y - 2), Precision), Precision, -1, 0, 0))
Else
ILoc = CStr(FormatNumber(Round(RetCoord(X - 2) - CenterPt(0), Precision), Precision, -1, 0, 0))
JLoc = CStr(FormatNumber(Round(RetCoord(y - 2) - CenterPt(1), Precision), Precision, -1, 0, 0))
End If

3. Thanks for the code. The chord length and radius are calculated in a similar way. But I'm unable to figure out how to calculate the start and end angles... at least, I did some calculations that turned out to be working. But in this specific drawing it doesn't. That sounds to me like there is a certain condition at which the code goes wrong.

Here is my code:
Code:
```function LWBulgeCalc(\$xs, \$xe, \$ys, \$ye, \$bulge)
{
\$result = array();

\$dx = \$xe - \$xs;
\$dy = \$ye - \$ys;
\$xmid = \$dx/2 + \$xs;
\$ymid = \$dy/2 + \$ys;

\$l = sqrt(pow(\$dx,2) + pow(\$dy,2)); //linelength from point 1 to point 2
// \$r = abs(\$l/(2* sin((4*atan(\$bulge))/2))); //another way of calculating the radius.

\$a = abs(\$bulge*\$l/2);
\$sb = \$bulge/abs(\$bulge);
\$theta_p = 4*atan(\$bulge);

if(\$dx != 0) \$theta_c = atan(\$dy/\$dx);
else \$theta_c = pi()/2;

if (\$dx > 0) \$sb *= -1;

\$cx = \$xmid + \$sb*(\$r-\$a)*sin(\$theta_c); //centerpoint X
\$cy = \$ymid - \$sb*(\$r-\$a)*cos(\$theta_c); //centerpoint Y

\$angle1 = asin((\$ye-\$cy)/\$r); //angle 1
\$angle2 = asin((\$cy-\$ys)/\$r); //angle 2

if(\$cx > \$xe) \$angle1 = pi() - \$angle1;
else \$angle1 = 2*pi() + \$angle1;

if(\$bulge < 0)	//CW
{
\$arcst =  \$angle1;
\$arcend = pi() + \$angle2;
}
else			//CCW
{
\$arcend = \$angle1;
\$arcst = pi() + \$angle2;
}

\$result[0] = \$cx;
\$result[1] = \$cy;
\$result[2] = \$r;
\$result[3] = \$arcst;
\$result[4] = \$arcend;

return \$result;
}```

4. So you're not creating g-code? I guess I didn't read your question correctly, because I don't need a start and end angle to create g-code.

If you have the center of the arc, the start and end angles should be 90° to a vector from the center to the start and end points, respectively. Right?

• No, I'm not converting to G-Code.

It is indeed possible to use sine/cosine/tan as I do have one 90 degree angle. The problem is that they only work with right angles but a circle is 360 degree.

When you compare the images, most of the arcs in the first image are similar to the second image, but some are not. So there must be a condition where the start and end angle are wrongly calculated and I can't figure out why.

I did find some code where they calculated the start and end angle but for some reason, that code doesn't work.
http://inkscape.modevia.com/doxygen/...rce.php#l00449

• Are these the angles you're trying to find?

• Well, indeed! How can I find those angles?

• I'm assuming you have AutoCAD. The top tool br has a radio button titled "dimension." Left click it, click "angle" click on the arc. Sometimes you need a Negative angle input, or you end up with a circle when the machine interprets what you want.

• First, I don't know the trig, and don't have time to find it.

Keep in mind that the angles are referenced from horizontal, with 0° to the right.

First find the angles from the center point to the start and ends of the arc. The Start and End angles are 90° greater for a CCW arc, and 90° less for a CW arc.

I've spent 45 minutes in AutoCAD playing with arcs, and I think that's correct. Should be simple to get your angles form this.

• Originally Posted by MrWild
I'm assuming you have AutoCAD. The top tool br has a radio button titled "dimension." Left click it, click "angle" click on the arc. Sometimes you need a Negative angle input, or you end up with a circle when the machine interprets what you want.

I guess it won't show a formula right? I need a formula so I only have to select the dxf file and the written software can calculate the rest of the needed data(with 100 arcs it's a lot of work to do it all manually).

• I tried to figure everything out for the last 5 hours with the new information(already spent 3 days on this issue) but I can't find a solution.

Most of the arcs are drawn the correct way, except for a few! Very annoying.
The dynamically created image can be found here: http://www.protoart.net/test/ndex.php

YES! I guess this is my lucky evening!
I still don't know exactly what I changed but luck is on my side and I changed the right values. Except for closing the drawing, everything goes as planned!

• If it's any consolation, it took me a lot longer than 3 days to get to the code I posted before.

• Page 1 of 2 12 Last