polynomials_on_simplices.calculus.angle module

Functionality related to angles and for computing angles between vectors.

class Dial[source]

Bases: object

A dial pointing at a position on a circle, while remembering the total number of laps it has turned around.

get_total_position()[source]

Get position the dial points at, including full revolutions.

Returns:Dial position in radians.
Return type:float
update_position(new_angle_pos)[source]

Set the new dial position, adjusting the number of laps if the dial crosses the discontinuity at \(\pm\pi\).

Parameters:new_angle_pos – New angle position the dial points at in the range \([-\pi, \pi)\).
compute_angle(v0, v1)[source]

Compute the angle between two vectors.

Parameters:
  • v0 – First vector.
  • v1 – Second vector.
Returns:

Angle between the two vectors (in \([0, \pi]\)).

degrees_to_radians(angle)[source]

Convert an angle from degrees to radians.

Parameters:angle – Angle in degrees.
Returns:Corresponding angle in radians.
Return type:float
direction(a0, a1)[source]

Compute the direction to go from a0 to a1.

Parameters:
  • a0 – First angle (in the range \([-\pi, \pi)\)).
  • a1 – Second angle (in the range \([-\pi, \pi)\)).
Returns:

1 if the shortest path from a0 to a1 goes anti-clockwise around the unit circle. -1 otherwise.

distance(a0, a1)[source]

Compute the distance between two angles (minimum distance along the unit circle).

Parameters:
  • a0 – First angle (in the range \([-\pi, \pi)\)).
  • a1 – Second angle (in the range \([-\pi, \pi)\)).
Returns:

Distance between the angles.

is_parallel(v0, v1)[source]

Check if two vectors are parallel.

Parameters:
  • v0 – First vector.
  • v1 – Second vector.
Returns:

True/False whether or not the two vectors are (approximately) parallel.

orthogonal_vector(v)[source]

Compute a vector which is orthogonal to the input vector \(v\).

Note

The returned orthogonal vector \(v^{\perp}\) satisfies \(\| v^{\perp} \| \geq \frac{2}{n} \| v \|\), where \(n\) is the dimension of the input vector \(v\).

Parameters:v – Non-zero n-dimensional vector.
Returns:n-dimensional vector which is orthogonal to the input vector.
Return type:Numpy array
orthonormal_frame(v, i=0)[source]

Compute an orthonormal frame R in 3d such that the i:th (i in {0, 1, 2}) column is parallel to the given vector v (\(R e_i = v, R^T R = R R^T = I\)). The two other columns could then be used as an orthonormal basis for the plane with normal v and which passes through the origin.

This is the unique rotation matrix R which rotates \(e_i\) to \(v\) without twist, i.e. vectors parallel to \(e_x \times v\) are kept fixed.

Parameters:
  • v – Non-zero 3d vector from which we compute the orthonormal frame (point where the derivative is evaluated).
  • i (int) – Column of the orthonormal frame which should be parallel to the input vector (i in {0, 1, 2}).
Returns:

Orthonormal frame (3 by 3 orthogonal matrix).

Return type:

Numpy array

radians_to_degrees(angle)[source]

Convert an angle from radians to degrees.

Parameters:angle – Angle in radians.
Returns:Corresponding angle in degrees.
Return type:float
to_centered_angle_interval(angle)[source]

Return the equivalent angle in the interval \([-\pi, \pi)\).

Parameters:angle – Angle in the range \((-\infty, \infty)\).
Returns:Equivalent angle in the range \([-\pi, \pi)\).
Return type:float
to_positive_angle_interval(angle)[source]

Return the equivalent angle in the interval \([0, 2 \pi)\).

Parameters:angle – Angle in the range \((-\infty, \infty)\).
Returns:Equivalent angle in the range \([0, 2 \pi)\).
Return type:float