CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > OpenSource CNC Design Center > Coding


Coding Post your Coding for opensource projects here.


This forum is sponsored by:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 07-24-2010, 07:37 AM
 
Join Date: Feb 2005
Location: The Netherlands
Posts: 120
fantasy2 is on a distinguished road
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..
Reply With Quote

  #2  
Old 07-24-2010, 08:54 AM
ger21's Avatar
Community Moderator
 
Join Date: Mar 2003
Location: Shelby Twp, MI....USA
Posts: 20,446
ger21 is on a distinguished road
Buy me a Beer?

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)
Reply With Quote

  #3   Ban this user!
Old 07-24-2010, 09:55 AM
 
Join Date: Feb 2005
Location: The Netherlands
Posts: 120
fantasy2 is on a distinguished road

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;
}
Reply With Quote

  #4  
Old 07-24-2010, 11:15 AM
ger21's Avatar
Community Moderator
 
Join Date: Mar 2003
Location: Shelby Twp, MI....USA
Posts: 20,446
ger21 is on a distinguished road
Buy me a Beer?

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)
Reply With Quote

  #5   Ban this user!
Old 07-24-2010, 11:27 AM
 
Join Date: Feb 2005
Location: The Netherlands
Posts: 120
fantasy2 is on a distinguished road

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
Reply With Quote

Sponsored Links
  #6  
Old 07-24-2010, 12:16 PM
ger21's Avatar
Community Moderator
 
Join Date: Mar 2003
Location: Shelby Twp, MI....USA
Posts: 20,446
ger21 is on a distinguished road
Buy me a Beer?

Are these the angles you're trying to find?
Attached Images
File Type: jpg angle1.jpg‎ (68.9 KB, 37 views)
__________________
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)
Reply With Quote

  #7   Ban this user!
Old 07-24-2010, 12:29 PM
 
Join Date: Feb 2005
Location: The Netherlands
Posts: 120
fantasy2 is on a distinguished road

Well, indeed! How can I find those angles?
Reply With Quote

  #8   Ban this user!
Old 07-24-2010, 01:04 PM
 
Join Date: Oct 2005
Location: US
Posts: 1,220
MrWild is on a distinguished road

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.
Reply With Quote

  #9  
Old 07-24-2010, 01:08 PM
ger21's Avatar
Community Moderator
 
Join Date: Mar 2003
Location: Shelby Twp, MI....USA
Posts: 20,446
ger21 is on a distinguished road
Buy me a Beer?

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)
Reply With Quote

  #10   Ban this user!
Old 07-24-2010, 01:11 PM
 
Join Date: Feb 2005
Location: The Netherlands
Posts: 120
fantasy2 is on a distinguished road

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).
Reply With Quote

Sponsored Links
  #11   Ban this user!
Old 07-24-2010, 03:38 PM
 
Join Date: Feb 2005
Location: The Netherlands
Posts: 120
fantasy2 is on a distinguished road

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 04:10 PM.
Reply With Quote

  #12  
Old 07-24-2010, 04:57 PM
ger21's Avatar
Community Moderator
 
Join Date: Mar 2003
Location: Shelby Twp, MI....USA
Posts: 20,446
ger21 is on a distinguished road
Buy me a Beer?

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)
Reply With Quote

Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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




All times are GMT -5. The time now is 06:21 AM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361