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 |