Skip to content

Commit 03aabb3

Browse files
committed
changed doc text, added angle_vectors_projected
1 parent 040a902 commit 03aabb3

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/compas/geometry/_core/angles.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ def angle_vectors(u, v, deg=False, tol=None):
7878
def angle_vectors_signed(u, v, normal, deg=False, tol=None):
7979
"""Computes the signed angle between two vectors.
8080
81-
It calculates the angle such that rotating vector u about the normal by
82-
angle would result in a vector that looks into the same direction as v.
81+
Returns the smallest angle between 2 vectors, with the sign of the angle based on the direction of the normal vector according to the right hand rule of rotation.
8382
8483
Parameters
8584
----------
@@ -120,6 +119,43 @@ def angle_vectors_signed(u, v, normal, deg=False, tol=None):
120119
else:
121120
return angle
122121

122+
def angle_vectors_projected(u, v, normal, deg=False, tol=None):
123+
"""Computes the signed angle between two vectors.
124+
125+
Retuns the angle between 2 vectors projected onto a plane defined by a normal vector.
126+
This can be positive or negative depending on the direction of the normal vector and the order of the input vectors
127+
128+
Parameters
129+
----------
130+
u : [float, float, float] | :class:`compas.geometry.Vector`
131+
XYZ components of the first vector.
132+
v : [float, float, float] | :class:`compas.geometry.Vector`
133+
XYZ components of the second vector.
134+
normal : [float, float, float] | :class:`compas.geometry.Vector`
135+
XYZ components of the plane's normal spanned by u and v.
136+
deg : bool, optional
137+
If True, returns the angle in degrees.
138+
tol : float, optional
139+
The tolerance for comparing values to zero.
140+
Default is :attr:`TOL.absolute`.
141+
142+
Returns
143+
-------
144+
float
145+
The signed angle in radians (in degrees if deg == True).
146+
147+
Examples
148+
--------
149+
>>> normal = [0.0, 0.0, 1.0]
150+
>>> angle_vectors_signed([0.0, 1.0, 0.0], [1.0, 0.0, 0.0], normal)
151+
-1.57079
152+
153+
"""
154+
u_cross = cross_vectors(u,normal)
155+
v_cross = cross_vectors(v,normal)
156+
157+
return angle_vectors_signed(u_cross, v_cross, normal, deg, tol)
158+
123159

124160
def angle_vectors_xy(u, v, deg=False, tol=None):
125161
"""Compute the smallest angle between the XY components of two vectors.

0 commit comments

Comments
 (0)