Jump to content
Sign in to follow this  
panta rhei

Arc centres of polylines

Recommended Posts

I thought this would be easy...

A user wants to place a stake (with x/y coordinates) at the centre of each arc in her polylines (plenty of them...)

The calculations seem to depend on the curvature of each arc (the famous clockwise conundrum revisited), but I can't figure out what triggers the dicotomy.

Here's what I am trying to get: dx & dy values like this (see attachment):

The code looks like this

PROCEDURE CentrePoints; 
VAR 
obHd : HANDLE; 
clockWise : BOOLEAN; 
t : INTEGER; 
x, y, dx, dy, a, aR, a1, a2, r, d, l : REAL; 
v1, v2 : VECTOR; 

BEGIN 
obHd := FSACTLAYER; 
GETPOLYPT(obHd, 1, x1, y1); 
GETPOLYLINEVERTEX(obHd, 2, x2, y2, t, r); 
GETPOLYPT(obHd, 3, x3, y3); 

v1.x := x2-x1; v1.y := y2-y1; 
v2.x := x3-x2; v2.y := y3-y2; 
a1 := VEC2ANG(v1); 
a2 := VEC2ANG(v2); 

a := ((180-ANGBVEC(v1, v2))/2); 
aR := TAN(DEG2RAD(a)); 


d := r/aR; 
l := SQRT(r^2+d^2); 

a := DEG2RAD(a-a1);
dx := l*COS(a);  
dy := l*SIN(a); 

LOCUS(x2-dx, y2+dy);

clockWise := GETOBJECTVARIABLEBOOLEAN(obHd, 652); 
MESSAGE(clockWise); { if FALSE, this works } 

END; 

RUN(CentrePoints); 

and works when the clockwiseness is False.

Also, I may be on the wrong track entirely.

Share this post


Link to post

Hi Petri,

???You almost had it. With a few minor changes it now works.

Raymond

PROCEDURE CentrePoints;

VAR

???obHd : HANDLE;

???clockWise : BOOLEAN;

???t : INTEGER;

???x, y, dx, dy, a, aR, a1, a2, r, d, l : REAL;

???x1, y1, x2, y2, x3, y3 : REAL;???{ added these to make it compile }

???v1, v2 : VECTOR;

BEGIN

???obHd := FSACTLAYER;

???GETPOLYPT(obHd, 1, x1, y1);

???GETPOLYLINEVERTEX(obHd, 2, x2, y2, t, r);

???GETPOLYPT(obHd, 3, x3, y3);

???

???v1.x := x1-x2; v1.y := y1-y2;??????{ make vector v1 point away from point 2 }

???v2.x := x3-x2; v2.y := y3-y2;??????{ yes, points away from point 2 }

???a1 := VEC2ANG(v1);

{??a2 := VEC2ANG(v2);}????????????????{ don't need this anymore }

???a := ANGBVEC(v1, v2)/2;??????????{ remove 180 from calculation, as v1 is now reversed }

???aR := TAN(DEG2RAD(a));

???d := r/aR;

???l := SQRT(r^2+d^2);

???

???{ use clockWise condition to add or subtract angle a to/from angle a1 }

???clockWise := GETOBJECTVARIABLEBOOLEAN(obHd, 652);

???if clockWise then a := DEG2RAD(a1+a)

???else a := DEG2RAD(a1-a);

???

???dx := l*COS(a);

???dy := l*SIN(a);

???LOCUS(x2+dx, y2+dy);

END;

RUN(CentrePoints);

Share this post


Link to post

Thank you very much, Ray! Got it to work.

Some puzzling questions still remain. In a polyline with more than one arc, there seems to be the curvature issue for each. Oddly enough, it also seems that if the polyline is clockwise, all works fine here in the lab at least. (Fortunately I have a ?reverse direction? command in my kit and this solves the situation.)

Another one is that if the radius is ?illegal? (too large), the polyline data contains the specified radius and there doesn't seem to be a way to inquire the radius actually applied.

(Maybe I have to decompose a copy, check the radii and adjust them?)

Share this post


Link to post

Petri

This is the response that I received from Nemetschek's CTO regarding increasing arc polyline radius when the tangent distance of the arc is > than 1/2 the distance between intersection points.: "The fix is Deep in the code, and it is risky to fix at this point. The work around is explained in the attached file: I?ve created the desired poly by setting the first arc then decomposing and composing the polyline, And finally set the radius of the second arc."

Share this post


Link to post

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.

Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...