Vector.AngleWithVector- sort by coordinates

We wanted to sort the first vector and the second vector, which were created in our study, according to the angles. When the angle made by each of the points exceeds 180 degrees, an error occurs in the calculation. that is, when it exceeds 180+a, it only calculates as a. How to can write a code when the angle exceeds 180 degrees.

Your rotationAxis should be the Z Axis since that’s what you’re rotating about. Vector.AngleAboutAxis will then return the angle counter-clockwise from vector to otherVector.

Vector.AngleWithVector always returns the interior angle between vectors.

For non- plan applications you can take the rotation angle about the vector formed by the cross of the two vectors.

1 Like

If the vector X-value is less than 0, convert the angle to 360-a or else keep the angle as it is then it will fetch the correct value as shown below.

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
xval = IN[0]
angle = IN[1]

# Place your code below this line
o=[]
for x,a in zip(xval,angle):
    if x<0:
        o.append(360-a)
    else:
        o.append(a)
# Assign your output to the OUT variable.
OUT = o

Hope this helps!!!

That requires some assumptions that may not always be true. In order to consistently get the angle you’re after, you have to know the direction between angles (or the order of the vectors) for the angle you’re after.

1 Like