 # Iteration points

hello every body, i’ve got a closed polyline, and i would like to know how many 90° angles there is.

so i wrote:

``````    points=rs.CurvePoints(cont)
for i in range(0,len(points)-1):
angle=rs.Angle2( points[i] , points[i+1] , points[i+1] , points[i+2])

``````

if i have 4 points, i can have easely angle between

• line point 0 to point 1 and line point 1 to point 2
• line point 1 to point 2 and line point 2 to point 3
• line point 2 to point 3 and line point 3 to point 4,

but how can i script the line point 3 to point 4 and line point 4 to point 0?

how about something like `points[(i+2) % len(points]`

sorry but i don’t understand…  and do you know what does mean:

“Message: 2d0a1c6a-4414-41ad-aede-144a8efa83ed does not exist in ObjectTable”

``````angle=rs.Angle2( points , points , points[-1] , points[-2])
#should work even if the polyline is not closed, but probably doesn't make much sense in that case
``````

Probably means this object references something that you either deleted or doesn’t exist anymore because of some some operation - for example joining two objects results in a new single object id, but the original two ids are then gone.

how about this, may need `lp = len(points) -1` depending on whether the curve is closed… something like that …?

``````import rhinoscriptsyntax as rs

points=rs.CurvePoints(cont)
lp = len(points)
for i in range(lp):
angle=rs.Angle2( [points[i] , points[(i+1)%lp] ], [points[(i+1)%lp] , points[(i+2)%lp]])
print angle

``````

yes it is…
in

``````    surfs=rs.ExplodePolysurfaces(bloc)
sorted_surfs=sorted([(rs.SurfaceArea(surf),surf) for surf in surfs],reverse=True)
``````

if i delete (surfs), it delete (sorted_surfs) too…

Yes that’s it, thank you!!

@Dancergraham, how do you translate ` %lp` in real french, i made some test to understand, but i need to translate this ‘notion’ to remember it.

C’est le modulo : par exemple modulo 4 on compte 0,1,2,3,0,1,2,3,0…

C’est le reste lorsqu’on divise par 4.

i knew modulo, but i didn’t know where i can use it… but know, i know!!! i’ll remember it??? not sure! 1 Like

The modulus is a pretty simple concept, just don’t overthink it and you’ll remember! It simply returns the remainder of the division of the first number to the second.
For example:

• `2 % 2 = 0`, because 2 fits entirely into 2, and thus 0 remains
• `2 % 3 = 1`, because 2 fits once into 3, and thus 1 remains
• `6 % 4 = 2`, because 4 fits once into 4, and 2 remains

Other than for simply finding the remainder and/or for the case that @Dancergraham already explained, it can for instance be used to deduce if a number is odd or even, meaning divisible by 2 with a remainder of 0:

``````for i in range(10):
if i % 2 == 0:
print i, "-> even"  # remainder is 0
else:
print i, "-> odd"  # remainder is 1 or greater
``````

Similar to the example above, it can also be used to create “cyclical” iterations, which will reset once they achieve a certain index:

``````i = 0  # initial index

while True:
i = (i + 1) % 6  # update the index and resets when i = 5, because (5 + 1) % 6 = 0
``````

These are the most common uses I’ve seen, but there are many others.