# If statement

Hi everybody,
I made a function to define if the polylines of a plan are: rectangle, circle, rectangle+segment, rectangle+2 segments.
I want to make a function to extract the largest segment of a polyline. any suggestions

What does this have to do with the thread title â€śIf statementâ€ť?

longest_segment_2018Jan31a.gh (8.5 KB)

Can use Segment Lengths + Subcurve.

LongestSeg.gh (5.3 KB)

Also confused by the titleâ€¦

1 Like

Iâ€™ve never noticed the Segment Lengths parameter before. One can learn so much by reading other peopleâ€™s code! Too bad that so many people donâ€™t bother, interested only in their own belly button.

2 Likes

Thank you, in the case of a rectangle itâ€™s ok but when itâ€™s a segment + arc or rectangle + 2 arcs or rectangle +1 arc ,the arc can be the longest segment. And for me I want to know the longest straight segment.

Here is what I would do, uses a simple c# component just to get the curve degree of each segment (donâ€™t think any gh component outputs curve degree unless I am missing it somewhere). Line type curves will be degree 1 (NURBS degree 3, Arcâ€™s degree 2) Then you use that as a culling test to which you would then use @Joseph_Oster method after.

LongestSegLine-PolyCurve.gh (12.3 KB)

1 Like

Moving the goal posts, eh? You didnâ€™t mention that in your OP and havenâ€™t provided a model to work with, so really, we canâ€™t read your mind. Itâ€™s not difficult to distinguish between straight lines and curves.

longest_segment_2018Jan31b.gh (10.4 KB)

I just counted control points and culled/ignored segments with more than two.

1 Like

You might want to simplify the curve first - lines can have more than two control points depending on how they are drawn. With simplify added I think it will be a good test. Still a component outputting degree seems useful. Maybe a wish for GH2.

I think youâ€™re right, thatâ€™s a bit of an oversight.

4 Likes

You could also compare the measured length of the curve and the distance between the end-points. For linear curves those two numbers will be nearly identical.

1 Like

I think the same is true for surface U and V degree. Degree is a useful test for culling in many cases.