Jump to content

3D Polyline length

Recommended Posts

Hi Sam,

   After a quick search, I could not find a function that works on 3D Poly, like hPerim() works on 2D Polys. It may be out there, but I could write the routine to sum the legs faster than I could search for a function that does or doesn't exist. But, @Pat Stanford is correct, I've already done that and found one in my script archive. Damn, I wrote it more than a decade ago. I'm getting old.


   Hey, it's another example using Vectors. DOUBLE BONUS!

PROCEDURE Get3DPolyLen_Example; 
{ 20 Dec 2008 - Raymond J Mullin } 

	function Get3DPolyLen(H :Handle) :Real;
	{ Return the perimiter length of 3DPoly H. If H is not a 3DPoly, return 0. }
		I, N :Integer; 
		L :Real; 
		P0, Pa, Pb :Vector;
		L := 0;
		if (GetType(H) = 25) then begin 
			N := GetVertNum(H); 
			GetPolyPt3D(H, 0, P0.x, P0.y, P0.z);	{ 1st vertex }
			Pa := P0;		{ copy of 1st vertex }
			for I := 1 to N-1 do begin 
				GetPolyPt3D(H, I, Pb.x, Pb.y, Pb.z); 	{ vertices 2 through N }
				L := L + Norm(Pb-Pa);		{ NORM is the vector DISTANCE function }
				Pa := Pb;
			end;		{ for }
			if IsPolyClosed(H) then  
				L := L + Norm(P0-Pb);	{ distance from last to first points }
		end;		{ if GetType }
		Get3DPolyLen := L;
	End;		{ Get3DPolyLen }

	AlrtDialog(concat('3D Poly Length = ', Num2StrF(Get3DPolyLen(FSActLayer)))); 





PS - if a native function exists, my bet is @Julian Carr or @JBenghiat would know.

Link to comment

This might be quicker. Convert a copy to nurbs then get its length using HLength():


Procedure T;
    hTemp, h3DPoly : HANDLE;
    h3DPoly := FSActLayer;
    hTemp := ConvertToNURBS(h3DPoly, True);
    Message('3D Poly Length: ', HLength(hTemp));

Link to comment

Hi Julian,

   Interesting approach. I knew you'd approach it differently than I. When you said your code might be quicker, it got me thinking. Your code is definitely more concise (quicker to code), but with the create and delete operations the execution speed can be an issue if large numbers of Polys need processing.


   For small object counts (<1000), both routines execute fast enough to be efficient. However, given enough objects the NURBS routine can appear painfully slow. I measured the two routines processing 1K, 10K, and 100K 3D Polygons. Each poly had 10 vertices. Here's what I got.


   Poly  |       JC        RM    |      JC         RM

Count  |    Ticks    Ticks  |    Time     Time

    1K    |       57           4    |     .95s       .07 s

  10K    |    551         21    |    9.2 s     0.35 s

100K    |  5586      175    |  93.1 s     2.92 s


   Sam, Bottom Line: pick the routine that will work best for your application based on your expected object count. 1-1000 Polys, shorter code looks better and is easier to support. >1000 Polys, summing the vertex distances will be much faster. VectorScript can get data from objects and process numbers and calculations much faster than it can create and delete objects. Just something to keep in mind when designing your coding approach.




Link to comment
  • 3 years later...

I am here because I drew a 3d Poly to represent an audio cabling run.  Since the cable is expensive, it would be great to have a worksheet quickly add up and compare the lengths of various routing combinations. This would seem like a very import function to have for ducting, cabling, piping, etc. Is there a tool in the piping or ducting tool set that does this?

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.

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