He everybody!

I have a problem that I am not able to fix. I added a portion of my script to show what I need:

I need to convert angles to percentages but it is not like 0° = 0% or 360° = 100%. It is like this:

0° = 100%

90° = 0%

180° = 100%

270° = 0%

45° = 50%

I measure from the Y axis, but ofcourse, it is possible to measure from the X axis also if this makes more sense.

Somehow I cannot come up with the right equation and get it to work in grasshopper, if there is anybody who has a clue, don’t hesitate

Stijn

angles to percentages.gh (14.1 KB)

Thank you for this qucik response! This seems to work, only not with 90° corners?

I think this is what I was looking for! thanks a lot

Ah, no when I use it in my script attached, it does not give the right output:

angles to percentages v02.gh (15.6 KB)

ftzuk
(Ftzuk)
5
Haven’t integrated it into your script but this might help.

ANGLE.gh (9.0 KB)

2 Likes

Quan_Li
(Quan Li)
6
angles to percentages v3.gh (16.9 KB)

Might one day it will end the life of this forum

```
def angle_to_percentage(angle):
"""Converts an angle in degrees to a percentage between 0 and 100.
Args:
angle: The angle in degrees (0 to 359).
Returns:
The corresponding percentage (0 to 100).
"""
angle = angle % 360
if angle < 90:
return angle / 90 * 100
elif angle < 180:
return 100 - (angle - 90) / 90 * 100
elif angle < 270:
return (angle - 180) / 90 * 100
else:
return 100 - (angle - 270) / 90 * 100
a= angle_to_percentage(angle)
```

2 Likes

Using trigonometry, it could be solved like this:

angle_to_percentage_trigonometry.gh (19.3 KB)

2 Likes

Thanks to all the contribution! I think it’s working, doing the first tests with it.

I’m using it for a rotary axis 3d printer!

Stijn