Page 1 of 2 12 LastLast
Results 1 to 12 of 15

Thread: Finding arc angles

  1. #1
    Registered
    Join Date
    Feb 2005
    Location
    The Netherlands
    Posts
    123
    Downloads
    0
    Uploads
    0

    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. #2
    Community Moderator ger21's Avatar
    Join Date
    Mar 2003
    Location
    Shelby Twp, MI....USA
    Posts
    22,289
    Downloads
    0
    Uploads
    0
    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
    Gerry

    Mach3 2010 Screenset
    http://home.comcast.net/~cncwoodworker/2010.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)


  3. #3
    Registered
    Join Date
    Feb 2005
    Location
    The Netherlands
    Posts
    123
    Downloads
    0
    Uploads
    0
    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*(($bulge*$bulge)+1)/$bulge/4); //Radius circle
    	// $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;
    	}
    
    	$arcst = rad2deg($arcst);
    	$arcend = rad2deg($arcend);
    
    
    
    	$result[0] = $cx;
    	$result[1] = $cy;
    	$result[2] = $r;
    	$result[3] = $arcst;
    	$result[4] = $arcend;
    
    	return $result;
    }


  4. #4
    Community Moderator ger21's Avatar
    Join Date
    Mar 2003
    Location
    Shelby Twp, MI....USA
    Posts
    22,289
    Downloads
    0
    Uploads
    0
    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?
    Gerry

    Mach3 2010 Screenset
    http://home.comcast.net/~cncwoodworker/2010.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)


  • #5
    Registered
    Join Date
    Feb 2005
    Location
    The Netherlands
    Posts
    123
    Downloads
    0
    Uploads
    0
    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


  • #6
    Community Moderator ger21's Avatar
    Join Date
    Mar 2003
    Location
    Shelby Twp, MI....USA
    Posts
    22,289
    Downloads
    0
    Uploads
    0
    Are these the angles you're trying to find?
    Attached Images Attached Images
    Gerry

    Mach3 2010 Screenset
    http://home.comcast.net/~cncwoodworker/2010.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)


  • #7
    Registered
    Join Date
    Feb 2005
    Location
    The Netherlands
    Posts
    123
    Downloads
    0
    Uploads
    0
    Well, indeed! How can I find those angles?


  • #8
    Registered
    Join Date
    Oct 2005
    Location
    US
    Posts
    1,237
    Downloads
    0
    Uploads
    0
    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.


  • #9
    Community Moderator ger21's Avatar
    Join Date
    Mar 2003
    Location
    Shelby Twp, MI....USA
    Posts
    22,289
    Downloads
    0
    Uploads
    0
    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.
    Gerry

    Mach3 2010 Screenset
    http://home.comcast.net/~cncwoodworker/2010.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)


  • #10
    Registered
    Join Date
    Feb 2005
    Location
    The Netherlands
    Posts
    123
    Downloads
    0
    Uploads
    0
    Quote Originally Posted by MrWild View Post
    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).


  • #11
    Registered
    Join Date
    Feb 2005
    Location
    The Netherlands
    Posts
    123
    Downloads
    0
    Uploads
    0
    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!
    Last edited by fantasy2; 07-24-2010 at 05:10 PM.


  • #12
    Community Moderator ger21's Avatar
    Join Date
    Mar 2003
    Location
    Shelby Twp, MI....USA
    Posts
    22,289
    Downloads
    0
    Uploads
    0
    If it's any consolation, it took me a lot longer than 3 days to get to the code I posted before.
    Gerry

    Mach3 2010 Screenset
    http://home.comcast.net/~cncwoodworker/2010.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)


  • Page 1 of 2 12 LastLast

    Similar Threads

    1. Help figuring out the angles
      By Shanghyd in forum Autodesk Software (Autocad, Inventor etc)
      Replies: 3
      Last Post: 04-14-2010, 12:15 AM
    2. Positive angles
      By GBRAVO in forum Visual Mill
      Replies: 0
      Last Post: 06-22-2009, 11:33 PM
    3. Newbie- CUTTING BEVELED ANGLES
      By mdyust in forum WoodWorking
      Replies: 3
      Last Post: 09-05-2008, 08:10 PM
    4. slopes and angles
      By massbaster in forum Sharp CNC
      Replies: 1
      Last Post: 07-11-2007, 11:14 PM
    5. how to mill angles?
      By cowanrg in forum General Metalwork Discussion
      Replies: 19
      Last Post: 05-14-2007, 10:35 AM

    Posting Permissions


     


    About CNCzone.com

      We are the largest and most active discussion forum from DIY CNC Machines to the Cad/Cam software to run them. The site is 100% free to join and use, so join today!

    Follow us on

    Facebook Dribbble RSS Feed


    Search Engine Friendly URLs by vBSEO ©2011, Crawlability, Inc.