Sam Jones Posted April 28, 2019 Share Posted April 28, 2019 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? Quote Link to comment
Pat Stanford Posted April 28, 2019 Share Posted April 28, 2019 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. Quote Link to comment
MullinRJ Posted April 29, 2019 Share Posted April 29, 2019 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. 1 Quote Link to comment
Julian Carr Posted April 29, 2019 Share Posted April 29, 2019 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); 1 Quote Link to comment
MullinRJ Posted April 29, 2019 Share Posted April 29, 2019 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 Quote Link to comment
Ian M. Posted June 22, 2022 Share Posted June 22, 2022 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? Quote Link to comment
MullinRJ Posted June 22, 2022 Share Posted June 22, 2022 Hello @Ian M., Though I don't have one written, it is possible to write a script that can be called by a worksheet to get your cable lengths. I think @Pat Stanfordor @michaelkmay have posted some example scripts in the past. Search the Forum for "Worksheet Script" (include the double quotes), or start here: A Pat Stanford Worksheet Script Tutorial. Raymond Quote Link to comment
Recommended Posts
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.