Jump to content
Developer Wiki and Function Reference Links ×

calculate arc center from polyline arc segment


Hannes L

Recommended Posts

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:

Link to comment
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 by DWorks
Link to comment

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);

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...