Sam Jones 46 Posted April 28 Is there a way to retrieve the length of a 3D Poly? Do I have to get the vertices locations with GetPolyPt3D and then compute the distances between them? Share this post Link to post

Pat Stanford 505 Posted April 28 Unless @MullinRJ or @JBenghiat or @Julian Carr has a solution, I think you need to write your own subroutine to walk the vertices and add up the lengths. I would probably just write a function to take the object handle and walk the vertices and use Distance3D to get the distances. Share this post Link to post

MullinRJ 97 Posted April 29 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. } Var I, N :Integer; L :Real; P0, Pa, Pb :Vector; Begin 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 } BEGIN AlrtDialog(concat('3D Poly Length = ', Num2StrF(Get3DPolyLen(FSActLayer)))); END; Run(Get3DPolyLen_Example); HTH, Raymond PS - if a native function exists, my bet is @Julian Carr or @JBenghiat would know. Share this post Link to post

Julian Carr 24 Posted April 29 This might be quicker. Convert a copy to nurbs then get its length using HLength(): Procedure T; VAR hTemp, h3DPoly : HANDLE; BEGIN h3DPoly := FSActLayer; hTemp := ConvertToNURBS(h3DPoly, True); Message('3D Poly Length: ', HLength(hTemp)); DelObject(hTemp); END; Run(T); Share this post Link to post

MullinRJ 97 Posted April 29 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. HTH, Raymond Share this post Link to post