1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//! Tools for working with angles specifically in 2D
use crateAngleDir;
use crate;
use ;
/// Convenience function for creating a rotation matrix for a rotation of 90 degrees in the
/// specified direction. A counter-clockwise rotation corresponds with a positive angle, and a
/// clockwise rotation corresponds with a negative angle.
///
/// # Arguments
///
/// * `dir`: The direction of the rotation
///
/// returns: Isometry<f64, Unit<Complex<f64>>, 2>
///
/// # Examples
///
/// ```
/// use approx::assert_relative_eq;
/// use engeom::AngleDir::{Ccw, Cw};
/// use engeom::geom2::{Point2, rot90};
///
/// let p_ccw = rot90(Ccw) * Point2::new(1.0, 0.0);
/// let p_cw = rot90(Cw) * Point2::new(1.0, 0.0);
///
/// assert_relative_eq!(p_ccw, Point2::new(0.0, 1.0));
/// assert_relative_eq!(p_cw, Point2::new(0.0, -1.0));
/// ```
/// Convenience function for creating a rotation matrix for a rotation of 270 degrees (-90) in the
/// specified direction. A counter-clockwise rotation corresponds with a positive angle, and a
/// clockwise rotation corresponds with a negative angle.
///
/// # Arguments
///
/// * `dir`:
///
/// returns: Isometry<f64, Unit<Complex<f64>>, 2>
/// Compute the signed angle from vector `v1` to vector `v2`. The sign of the angle is positive if
/// the shortest rotation from `v1` to `v2` is counter-clockwise, and negative if it is clockwise.
/// The angle is measured in radians, and will be in the range [-pi, pi].
///
/// Alternately, you can think of the angle as the amount of rotation needed to rotate `v1` to
/// match the direction of `v2`.
///
/// # Arguments
///
/// * `v1`: The reference vector
/// * `v2`: The vector to which the angle is measured
///
/// returns: f64
///
/// # Examples
///
/// ```
/// use approx::assert_relative_eq;
/// use engeom::Vector2;
/// use engeom::geom2::signed_angle;
///
/// let v = Vector2::new(1.0, 0.0);
///
/// let a0 = signed_angle(&v, &Vector2::new(1.0, 1.0));
/// assert_relative_eq!(a0.to_degrees(), 45.0);
///
/// let a1 = signed_angle(&v, &Vector2::new(1.0, -1.0));
/// assert_relative_eq!(a1.to_degrees(), -45.0);
///
/// let a2 = signed_angle(&v, &Vector2::new(-1.0, 1.0));
/// assert_relative_eq!(a2.to_degrees(), 135.0);
///
/// let a3 = signed_angle(&v, &Vector2::new(-1.0, -1.0));
/// assert_relative_eq!(a3.to_degrees(), -135.0);
/// ```
/// Returns the angle between two vectors, in radians, in the direction specified. This can be
/// thought of as the amount of rotation needed to rotate `v1` to match the direction of `v2` when
/// rotating only in `direction`. The angle will be in the range [0, pi].
///
/// # Arguments
///
/// * `v1`: The reference vector
/// * `v2`: The vector to which the angle is measured
/// * `direction`: The direction in which to measure the angle
///
/// returns: f64
///
/// # Examples
///
/// ```
/// use approx::assert_relative_eq;
/// use engeom::geom2::{Vector2, directed_angle};
/// use engeom::AngleDir::{Ccw, Cw};
///
/// let v = Vector2::new(1.0, 0.0);
///
/// let v0 = Vector2::new(1.0, 1.0);
/// assert_relative_eq!(directed_angle(&v, &v0, Ccw).to_degrees(), 45.0);
/// assert_relative_eq!(directed_angle(&v, &v0, Cw).to_degrees(), 315.0);
/// ```