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 02-19-2009, 10:48 PM
 
Join Date: May 2003
Location: Australia
Posts: 33
babinda01 is on a distinguished road
Offset Algorithm

Hi
I am trying to write a simple 2.5d cam program, for a specific special purpose machine.
Does anyone have an example code of creating offsets and/or for pocketing of a dxf file. I can easily read a dxf and convert it to gcode, but I want to be able to apply an offset either inside or outside the line. And also to pocket within the shape. I don't want to use offset left/right gcodes, I need to be able to actually offset the toolpath.

Regards
Andrew
Tweet this Post!Share on Facebook
Reply With Quote

  #2   Ban this user!
Old 02-20-2009, 09:00 AM
 
Join Date: Sep 2004
Location: USA
Posts: 145
Dan Falck is on a distinguished road
offseting

This might help you:
http://code.google.com/p/libarea/

Also, check out HeeksCAD/HeeksCNC:

http://code.google.com/p/heekscnc/

Dan
Tweet this Post!Share on Facebook
Reply With Quote

  #3   Ban this user!
Old 02-22-2009, 06:03 AM
 
Join Date: May 2003
Location: Australia
Posts: 33
babinda01 is on a distinguished road
Offset Algorithm

Hi Dan

Thanks for your reply. The first link you sent looks very promising. I am madly porting it over to C#.

Thanks again

Andrew
Tweet this Post!Share on Facebook
Reply With Quote

  #4   Ban this user!
Old 12-02-2009, 04:29 PM
bradodarb's Avatar  
Join Date: Oct 2004
Location: usa
Posts: 121
bradodarb is on a distinguished road
C# port

Were you able to port over to c# successfully?
Tweet this Post!Share on Facebook
Reply With Quote

  #5   Ban this user!
Old 12-02-2009, 04:51 PM
 
Join Date: May 2003
Location: Australia
Posts: 33
babinda01 is on a distinguished road

Hi
No - I just havn't managed to find the time. I have too many projects and not enough time.....
It is still on my to-do list.

Regards
Andrew
Tweet this Post!Share on Facebook
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 12-03-2009, 12:50 AM
bradodarb's Avatar  
Join Date: Oct 2004
Location: usa
Posts: 121
bradodarb is on a distinguished road

I am thinking at the moment it might be as fast or faster to write it from scratch.... been resarching the math all week. Right now I can offset lines, arcs and fillet two lines easily enough. Where I am stumped is filleting two arcs or a line and arc combo. I have some pretty robust geometry entit classes with WPF graphics support (for verification). Once the remaining filleting operations are implemented I will be happy to share. Any help is greatly apreciated. .... Back to the math lab
Tweet this Post!Share on Facebook
Reply With Quote

  #7   Ban this user!
Old 12-14-2009, 07:22 PM
 
Join Date: Feb 2007
Location: canada
Posts: 559
Larken is on a distinguished road

I worked a lot in the 90's trying to write an offset for my Lcam program. I had a basic one but would make loops when the cutter went into some tight places with a lot of small vectors.
I write in Delphi, are you using C+ ?

I figured out now, how to make a perfect offset and how they do it in Corel draw using a thick line to clear the path of any loops and knots. I just don't have the time or mental ambition right now to code it.

There are a lot of tricks to analyze vector chains. I know how to determine path direction, whether one chain is inside an other etc.

Check out my StarCam. Its layout program for CNC that goes in front of my CNC controller. I would like to add a Cutter offset some day and a Fill routine.

http://www.larkencnc.com/dloads/index.shtml

I'm possibly looking for some one to write an offset for it in Delphi

Larry K
__________________
Manufacturer of CNC routers and Viper Servo Drives
www.LarkenCNC.com and www.Viperservo.com
Tweet this Post!Share on Facebook
Reply With Quote

  #8   Ban this user!
Old 04-23-2010, 04:53 AM
 
Join Date: Oct 2008
Location: Canada
Posts: 240
Jack000 is on a distinguished road

any progress on your code? I'm also writing a 2.5d cam program, and offsets have caused a lot of headaches. From a cursory look at libarea, they seem to be breaking the paths into points, and matching lines and circular arcs to the points?

The approach I've gone with is to approximate the path with biarcs and lines, and offsetting the resulting approximation. This makes things a lot simpler because unlike beziers, biarcs and lines have exact offsets.

The problem lies in eliminating self-intersections of the offset path. Right now I'm doing a brute force thing - find all intersections and eliminate segments based on the normal of the offset path, but clearly this is an O(n^2) operation and not optimal.

I wonder how commercial cam packages do it. I've read things about voronoi diagrams and distance maps, but the math is a bit over my head..

I'm also curious about efficient algorithms for computing path winding direction. I know about the point in polygon method, but what if you don't have a point? The method that comes to mind involves calculating the polygonal area and checking whether it's positive or negative. Is there a more efficient approach?
__________________
___________________________
www.carveit.ca
Tweet this Post!Share on Facebook
Reply With Quote

  #9   Ban this user!
Old 04-26-2010, 01:19 PM
 
Join Date: Feb 2007
Location: canada
Posts: 559
Larken is on a distinguished road

I guess you know some of the tricks.
- First make contours closed.
- Make your contour CW
- Offset the chain of arcs and lines.
- You can Find all intersections using line intersect routines
- create closed contours of all intersection loops
- Bad loops will be CCW (erase them)

Breaking objects to points is not the way to go. Its very slow cam programs don't do it this way.


Here is my intersection procedure (pascal) for lines. I wrote this years ago.

Procedure intersect(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2:real;online:boolean);
var xla,xlb,ma,mb,a1,a2,b1,b2,cc1,cc2,det:real;
begin
parallel:=false; linescross:=false;
xla:=xa2-xa1; xlb:=xb2-xb1;
if (xa1-xa2=0) and (ya1-ya2=0) then parallel:=true;
if (xb1-xb2=0) and (yb1-yb2=0) then parallel:=true;
if (xla=0) or (xlb=0) then
begin
if (xla=0) and (xlb=0) then parallel:=true;
if parallel=false then begin
if xla<>0 then
begin
ma:=(ya2-ya1)/(xa2-xa1);
cc1:=ma*xa1-ya1;
yint:=ma*xb1-cc1; xint:=xb1;
end else
begin
mb:=(yb2-yb1)/(xb2-xb1);
cc2:=mb*xb1-yb1;
yint:=mb*xa1-cc2; xint:=xa1;
end;
end;
end
else begin
ma:=(ya2-ya1)/(xa2-xa1); mb:=(yb2-yb1)/(xb2-xb1); b1:=-1; b2:=-1;
if abs(ma-mb)<0.00001 then parallel:=true;
cc1:=-(ma*xa1-ya1); cc2:=-(mb*xb1-yb1);
det:=((ma*b2)-(b1*mb));
if det<>0 then begin
xint:=((cc2*b1)-(cc1*b2))/det;
yint:=((cc1*mb)-(ma*cc2))/det;
end
else parallel:=true;
end;

if (not parallel) and online then {check if intersect is in range of LINE }
begin
if ((xint>=xa1) and (xint<=xa2)) or ((xint>=xa2) and (xint<=xa1))
then if ((yint>=ya1) and (yint<=ya2)) or ((yint>=ya2) and (yint<=ya1))
then if ((xint>=xb1) and (xint<=xb2)) or ((xint>=xb2) and (xint<=xb1))
then if ((yint>=yb1) and (yint<=yb2)) or ((yint>=yb2) and (yint<=yb1))
then begin linescross:=true; end;
end;
end;


Larry K
__________________
Manufacturer of CNC routers and Viper Servo Drives
www.LarkenCNC.com and www.Viperservo.com
Tweet this Post!Share on Facebook
Reply With Quote

  #10   Ban this user!
Old 04-26-2010, 03:22 PM
 
Join Date: Nov 2008
Location: Austria
Posts: 18
grg12 is on a distinguished road

Hallo

I'm working on simple dxf->g-code conversion tool - current version is available at http://members.chello.at/grzegorz12/.../DXFKornik.rar . This rar contains all sources and executable - to start it you need QT4.1 library (available at http://qt.nokia.com/products/library...-class-library ), program is writen in C++, configured for VisualStudio 2003). I have started this project over 4 months ago, hoping that it will take 3, max 4 weeks - and it's still waaaay from being ready.
Unfortunetly offseting algorithm is far more complex than i thought - offseting line/circle/arc primitives is easy - real problems begin at this point.
Short descrition of current version of algorithm:
Basic "unit" is class PathPrimitive that could be line, circle, arc or list of primitives. Special type of primive is "chain" -> list of connected primitives.
Offseting algorithm (childPathGenerator) goes over "chain" components and creates offseted primitives (to offset a line you need to move it's endpotins over a vector perpendicular to line, to offset arc/circle you must change it's radius - thats all), every time new offseted object is created algorithm checks if a "connector arc" is needed to connect it to previous component. Algorithm uses tangent angles at endpoints of components to calculate if connector arc is needed and how the arc should look like. At this point we have collection of small "chains" - broken at points where offseted primiteves cross each other. To connect that mess into pretty chain algorithm must cut and throw away "swarf". To do this algothim tries to find crosspoints between all primiteves in list (all to all) - every cross point is added in special list with info "good->bad", "bad->good" (decision is based on tangent angles at cross point - basically when you go "away" from orginal path it's bad2good). After all primitves are checked algorithm scans this list - everything between "bad->good" and "good->bad" is saved, other parts are cut away. At this point our "chain" is almost clean - but in sometimes it's not a chain anymore - in some cases offseted chain breaks into collection of loops (example - big circles connected with thin "pipe" when offset is bigger than "pipe" width...) and some stubborn swarf. So algorithm searches this list and collects connected primitives into chains - at the end all chains that are not closed (looped) are thrown away (if closed chain intersects all "good" parts must be looped)
And that's all, at last for today

Gregor
Tweet this Post!Share on Facebook
Reply With Quote

Sponsored Links
  #11   Ban this user!
Old 05-21-2010, 05:10 AM
 
Join Date: Oct 2008
Location: Canada
Posts: 240
Jack000 is on a distinguished road

grg12: that sounds exactly like what I'm doing :]

I also tried to implement the offset algorithm, almost exactly as you describe - using the normal vector as a criterion for good/bad. The problem I came across was that it doesn't seem to like multiple intersections between several internal invalid loops, which usually happens when you have a complex curve with a large offset radius.

I've instead gone with a bitmap approach, although that has its own problems.

One point to note is that finding all intersections between all segments is O(n^2) time complexity. This is really really bad. I have implemented a sweep-line algorithm for finding intersections with O(log m) complexity, which brought my processing time from over 5 seconds to under 200ms.

here's the paper, it's for polygonal chains, but it was pretty easy to adapt to circular arcs.
__________________
___________________________
www.carveit.ca
Tweet this Post!Share on Facebook
Reply With Quote

  #12   Ban this user!
Old 05-21-2010, 11:03 AM
 
Join Date: Feb 2007
Location: canada
Posts: 559
Larken is on a distinguished road

I though of the bitmap also, but it uses a lot of memory if resolution is very high and is slow.
There is a trick to creating the perfect offset with no overlaps. If you study corel draw8-10 (the best versions) they had a excellent fast clean, 'Contour' command it will give you some hints.

Gregor, how are you storing the vectors , using an array or linked list ?

Do you have a routine to tell if one chain is inside another ? Thats a hard one . I have one to tell if a contour is ccw or cw no matter how complex it is, but i havn't one to tell if its inside other chains yet.

at the end all chains that are not closed (looped) are thrown away (if closed chain intersects all "good" parts must be looped)
If your origional chain is CW and you do an intesection check and then join all closed chains. The Ones to keep will all be CW and the gouging (bad) ones (to erase) will all be CCW.
__________________
Manufacturer of CNC routers and Viper Servo Drives
www.LarkenCNC.com and www.Viperservo.com

Last edited by Larken; 05-21-2010 at 11:21 AM.
Tweet this Post!Share on Facebook
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
Algorithm? CNCgr OpenSource Software 16 12-07-2009 06:23 PM
Algorithm for G02 / G03 coding jemmyell Coding 19 08-06-2009 06:58 PM
Archimedean Spiral Algorithm fooo Coding 6 10-08-2007 11:28 PM
XY positioning algorithm needed Tracid PIC Programing / Design 4 11-28-2006 11:26 AM
Need Help With Circular Pocketing Algorithm lerman G-Code Programing 9 11-20-2006 05:41 PM




All times are GMT -5. The time now is 01:31 PM.





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