Jump to content
Sign in to follow this  
VectorGeek

CopyPoly() issues

Recommended Posts

Hi all,

This line of code:

newpolyh := OffsetPoly(oldpolyh,irailoffset,1,TRUE,TRUE,16,1);

results in a successful poly, offset from the source poly as expected. However, at every outside corner, there are two additional vertices (one in each direction from the corner point), offset by the irailoffset parameter. Not sure if I understand the parameters correctly. Can anyone suggest what I may be doing wrong?

I would use OffsetPolyN, however when used in a PIO, it forces the object to be deselected after every regen. A bug dating way back that hasn't been fixed in VW 2011 SP5 (have not tried VW 2012).

Thanks!

V-G.

Share this post


Link to post

Dear Mr. Geek,

???I am not sure this function is up for rigorous use. I just tried it and I could not get fractional offsets. Offset = 0.1 resulted in duplicating the poly with no offset. Offset = 1, 2, 3 all worked, but 1.1 did not.

???Have you looked at http://developer.vectorworks.net/index.php?title=VS:OffsetPoly? There are notes consistent with what I just found out and quite a bit more.

Good luck,

Raymond

Share this post


Link to post

I don't know that I'll be a lot of help, but I've been using both calls a fair amount.

This works just fine in both Metric and Imperial drawings:

NewObj:= OffsetPoly(OldObj,.0625",1,False,True,512,.03125"); (I'm trying to preserve curves best as possible.)

I've not seen the deselction issue w. OffsetPolyN (yet).

The frustrations I have had include:

- The 2 calls seem to "polygonize" reference polylines differently. The former seems to create an offset polygon automatically but I've had much better results using "ConvertToPolygon" before using that call. The latter seems to preserve the "polylineness" but seems to give "ClipSurface" issues, even when the offset is closed.

- I've learned to test for object type when using "OffsetPoly." Even when single polygons are created, they're sometimes contained in groups - especially, if I've done a negative offset.

My 2?...

Share this post


Link to post

Thanks Raymond and Andrew for looking at this. After more playing around, I think that OffsetPoly() is just plain broken.

OffsetPolyN() does result in the object being deslected after regen, however by adding a line in the PIO code to select:

SetSelect(parmHand);

that seems to fix it.

Many thanks.

V-G.

Purveyor of fine cigars and whiskey.

Edited by VectorGeek

Share this post


Link to post

For both OffsetPoly() and OffsetPolyN(), the offset varies from one side of the control line to the other, based on the "sense" of the poly. As the VSFR states:

"When offsetting an open polygon or polyline, the direction of the offset will depend on the overall sense of the poly. From start to end, if the poly turns right more than left, the offset will be to the left, if offsetDistance is positive."

What I need is a way to determine which direction the polygon is offsetting. I have played with various shapes, and can't seem to figure out what NVW means by the "sense" of the polygon, or what is meant by "turns right more than left".

Any ideas?

V-G

Share this post


Link to post

Dear Mr. G.,

???To find out what is meant by "turns right more than left", you must look at each turn individually and weigh the combined result. It's a pretty simple calculation carried to a meticulous end if the number of vertices is large. Be glad for your little computer friend.

???Every three points has an implied angle in the middle. "Simply" add up all the angles and compare the value to 0. If the answer is positive, you have turned left more than right, conversely if it is not positive you have not gone CCW. I'll leave it to you to decide which way you went if the answer is zero.

???There may be more elegant means afoot, but for me, the first thing that works is most often adequate. I've used the following routine with all the polys I've run into. It sums up all the left and right hand turns and spits out a verdict, but it does assume the poly to be non-intersecting (and >2 points).

???GetPolyPnt is one of my generic routines that returns only the point requested. If you are only processing polygons, then swap it out for GetPolyPt(), otherwise use the other one.

Happy cipherin',

Raymond

function IsCCW(H :Handle) :Boolean;
{ A goodly while ago - R. Mullin }
{ Return TRUE if Poly H is CCW, FALSE if it is CW. }
Var
I, VCnt :Integer;
ang :Real;
P1, P2, P3 :Vector;


function Turn(P1, P2, P3 :Vector) :Real;
{ Return the angle between vectors P2-P1 and P3-P2. CCW is Positive. }
Var
	P, V1, V2 :Vector;
Begin
	V1 := P2-P1;
	V2 := P3-P2;
	P := CrossProduct(V1, V2);
	If (P.z<0) then Turn := -AngBVec(V1, V2)
	else Turn := AngBVec(V1, V2);
End;		{ Turn }


Begin
VCnt := GetVertNum(H);
GetPolyPnt(H, 1, P1);
GetPolyPnt(H, 2, P2);
GetPolyPnt(H, 3, P3);
ang := Turn(P1, P2, P3);

I := 3;
while (I		I := I + 1;
	P1 := P2;
	P2 := P3;
	GetPolyPnt(H, I, P3);
	ang := ang + Turn(P1, P2, P3);
end;		{ while }

P1 := P2;
P2 := P3;
GetPolyPnt(H, 1, P3);
ang := ang + Turn(P1, P2, P3);

IsCCW := ang > 0;
End;		{ IsCCW }

Share this post


Link to post

That's GOLD Raymond. Thanks for posting. I figured it was something to do with the cumulative angles, however this definitely fast tracks me to finishing up my object.

Thanks a million!

V-G

Olympic Couch Surfing Champion.

Share this post


Link to post

Mr. G.,

???Here's some Platinum for your collection. Moments ago I was politely informed by an astute Finnish colleague of mine of a significantly more elegant way of divining the answer to your previous CW/CCW query. ObjectVariableBoolean - 652. It knows which way it goes. Thank you Mr. S.

???As I told him, I stop looking for answers to problems when I get my first working solution. I think that code snippet predated VW9, the version ObjectVariables arrived on the scene. More than a decade ago? I guess I can step into the 21st century now.

???Use it in good health.

Raymond (part time dinosaur)

Share this post


Link to post
Mr. G.,

???Here's some Platinum for your collection. Moments ago I was politely informed by an astute Finnish colleague of mine of a significantly more elegant way of divining the answer to your previous CW/CCW query. ObjectVariableBoolean - 652. It knows which way it goes. Thank you Mr. S.

???As I told him, I stop looking for answers to problems when I get my first working solution. I think that code snippet predated VW9, the version ObjectVariables arrived on the scene. More than a decade ago? I guess I can step into the 21st century now.

???Use it in good health.

Raymond (part time dinosaur)

Raymond,

My apologies for a slow response, however I have been holidaying and catching up on my celery consumption over the past week.

Thanks for this additional information. The fact that it came from Petri means that I will forever add the following line of code in any routine where I use it:

{the following routine graciously offered by Petri Sakinnen, giver of all that is good and vanguard of all things Finnish}

Namaste,

VectorGeek

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...