Hannes L Posted December 12, 2011 Share Posted December 12, 2011 Hello, I try to write a script which returns me the koordinates of each point of a polyline (arc and lines, no splines). With GetPolylineVertex(obj, vertexNum, ptX, ptY, vertexType, arcRadius) i get te several vertexes and radius, now i have to calculate the arc centres, but have no idea how to do that. Could please anyone give me a hint how to solve that, or does anyone have a script to share? Thanks a lot in Advance, Kind Regards, Hannes PS.: i hope u can read my poor english :blush: Quote Link to comment
Dieter @ DWorks Posted December 12, 2011 Share Posted December 12, 2011 If you know 2 points on a circle (or arc), you can find it's center. Graphically, you just draw 2 circles with the same radius as your arc and you will get 1 or 2 points of intersection. One of these points is the center. You can also get the mid point of the arc, and by this, you are certain wich point is the center. You can script this mathematically. Quote Link to comment
Miguel Barrera Posted December 12, 2011 Share Posted December 12, 2011 You can use vector geometry to get the center mathematically. 1. Get the vectors between pt1 & pt2 and pt2 & pt3. 2. Get the perpendicular vectors perpV1 & perpV2. 3. Get the perpendicular lines passing thru pt1 & pt3 4. Use LineLineIntersection procedure to find the arc center. Quote Link to comment
Hannes L Posted December 13, 2011 Author Share Posted December 13, 2011 Hello, Thank you Dworks and Miguel. I'll try the way as Miguel suggested. Its a little bit difficult for me, because my knowledge about vectormathematic is very little. So its time to learn more about it....:-) Quote Link to comment
Dieter @ DWorks Posted December 14, 2011 Share Posted December 14, 2011 (edited) Hello, Thank you Dworks and Miguel. I'll try the way as Miguel suggested. Its a little bit difficult for me, because my knowledge about vectormathematic is very little. So its time to learn more about it....:-) It's actually the same as mine, but with vectors. Mine is more graphical. But when you know Vectors, I would also use Miguel's method. Edited December 14, 2011 by DWorks Quote Link to comment
Miguel Barrera Posted December 14, 2011 Share Posted December 14, 2011 The following code makes use of vectors to calculate points which I think is simpler than using other methods. Note: 1. It is not bug free since there are special situations that must be handled before calling GetArcCenter. 2. Vectors can be displayed also as x,y,z but I chose the original vector notation v[1],v[2],v[3] to distinguish them from 2D/3D points. PROCEDURE GetPLineGeom; CONST kCORNER = 0; kBEZIER = 1; kCUBSPL = 2; kARCRAD = 3; VAR pLineHdl: HANDLE; vtxPt,pt1,pt3,arcCtr: POINT; i,vxTot,vxType: INTEGER; arcRad1,arcRad2,arcRad3: REAL; PROCEDURE GetArcCenter(vtxRad: REAL; VAR vtx1,vtx2,vtx3,ctrPt: POINT); VAR prpPt1,prpPt3: POINT; parLn,OnLn: BOOLEAN; tanLng,arcAng: REAL; vec1,vec2,prpVec1,prpVec2: VECTOR; BEGIN {vectors along tangent line} vec1[1]:= vtx1.x - vtx2.x; vec1[2]:= vtx1.y - vtx2.y; vec2[1]:= vtx3.x - vtx2.x; vec2[2]:= vtx3.y - vtx2.y; {This code segment will get the arc ends} {calculate length from vertex pt to the arc end} arcAng:= AngBVec(vec1,vec2); tanLng:= vtxRad / (Tan(Deg2Rad(arcAng/2))); {resize tangent vectors} vec1:= tanLng * UnitVec(vec1); vec2:= tanLng * UnitVec(vec2); {calculate the arc end points} vtx1.x:= vtx2.x + vec1[1]; vtx1.y:= vtx2.y + vec1[2]; vtx3.x:= vtx2.x + vec2[1]; vtx3.y:= vtx2.y + vec2[2]; {This will get the center} {get perpendicular vector to tangent line} prpVec1:= Perp(vec1); prpVec2:= Perp(vec2); {create points passing thru the end points} prpPt1.x:= vtx1.x + prpVec1[1]; prpPt1.y:= vtx1.y + prpVec1[2]; prpPt3.x:= vtx3.x + prpVec2[1]; prpPt3.y:= vtx3.y + prpVec2[2]; {calculate the intersection of the lines from the arc end points = arc center} LineLineIntersection(vtx1,prpPt1,vtx3,prpPt3,parLn,OnLn,ctrPt); END; BEGIN pLineHdl:= FSActLayer; IF (pLineHdl <> NIL) & (GetType(pLineHdl) = 21) THEN BEGIN vxTot:= GetVertNum(pLineHdl); FOR i:= 1 TO vxTot DO BEGIN GetPolylineVertex(pLineHdl,i,vtxPt.x,vtxPt.y,vxType,arcRad2); CASE vxType OF kCORNER: BEGIN WriteLn('Corner Pt ',i:0,' = ',Num2StrF(vtxPt.x),Num2StrF(vtxPt.y)); Tab(1); WriteLn('radius = ',Num2StrF(arcRad2)); END; kBEZIER: BEGIN WriteLn('Bezier Pt ',i:0,' = ',Num2StrF(vtxPt.x),Num2StrF(vtxPt.y)); Tab(1); WriteLn('radius = ',Num2StrF(arcRad2)); END; kCUBSPL: BEGIN WriteLn('Cubic Pt ',i:0,' = ',Num2StrF(vtxPt.x),Num2StrF(vtxPt.y)); Tab(1); WriteLn('radius = ',Num2StrF(arcRad2)); END; kARCRAD: BEGIN {Need to check if index is within array bounds} GetPolylineVertex(pLineHdl,i-1,pt1.x,pt1.y,vxType,arcRad1); GetPolylineVertex(pLineHdl,i+1,pt3.x,pt3.y,vxType,arcRad3); {If arcRad2 = 0, need to calculate max. radius} GetArcCenter(arcRad2,pt1,vtxPt,pt3,arcCtr); Locus(pt1.x,pt1.y); Locus(pt3.x,pt3.y); Locus(arcCtr.x,arcCtr.y); WriteLn('Arc Pt ',i:0,' = ',Num2StrF(vtxPt.x),Num2StrF(vtxPt.y)); Tab(1); WriteLn('radius = ',Num2StrF(arcRad2),'; center = ',Num2StrF(arcCtr.x),Num2StrF(arcCtr.y)); END; END; END; END; END; Run(GetPLineGeom); Quote Link to comment
Hannes L Posted December 15, 2011 Author Share Posted December 15, 2011 Miguel, Thank you, Thanks a lot!!! It works great. Now i can finish my Plugin for writing the CNC code for the CNC Router. Again, many Thanks!! Kind Regards, Hannes Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.