@@ -49,7 +49,7 @@ extension Quaternion {
49
49
/// - If a quaternion is not finite, its `.length` is `infinity`.
50
50
///
51
51
/// See also `.magnitude`, `.lengthSquared`, `.polar` and
52
- /// `init(length:argument :axis:)`.
52
+ /// `init(length:halfAngle :axis:)`.
53
53
@_transparent
54
54
public var length : RealType {
55
55
let naive = lengthSquared
@@ -70,26 +70,25 @@ extension Quaternion {
70
70
/// The squared length `(r*r + x*x + y*y + z*z)`.
71
71
///
72
72
/// This value is highly prone to overflow or underflow.
73
- ///
73
+ ///
74
74
/// For many cases, `.magnitude` can be used instead, which is similarly
75
75
/// cheap to compute and always returns a representable value.
76
76
///
77
77
/// This property is more efficient to compute than `length`.
78
78
///
79
79
/// See also `.magnitude`, `.length`, `.polar` and
80
- /// `init(length:argument :axis:)`.
80
+ /// `init(length:halfAngle :axis:)`.
81
81
@_transparent
82
82
public var lengthSquared : RealType {
83
83
( components * components) . sum ( )
84
84
}
85
85
86
- /// The principle argument (half rotation angle) in radians within
87
- /// *[0, π]* range.
86
+ /// The half rotation angle in radians within *[0, π]* range.
88
87
///
89
88
/// Edge cases:
90
- /// - If the quaternion is zero or non-finite, argument is `nan`.
89
+ /// - If the quaternion is zero or non-finite, halfAngle is `nan`.
91
90
@inlinable
92
- public var argument : RealType {
91
+ public var halfAngle : RealType {
93
92
guard isFinite else { return . nan }
94
93
// A zero quaternion does not encode transformation properties.
95
94
// If imaginary is zero, real must be non-zero or nan is returned.
@@ -104,61 +103,65 @@ extension Quaternion {
104
103
105
104
/// The [polar decomposition][wiki].
106
105
///
107
- /// Returns the length of this quaternion, argument in radians of range
106
+ /// Returns the length of this quaternion, halfAngle in radians of range
108
107
/// *[0, π]* and the rotation axis as SIMD3 vector of unit length.
109
108
///
110
109
/// Edge cases:
111
- /// - If the quaternion is zero, length is `.zero` and argument and axis
110
+ /// - If the quaternion is zero, length is `.zero` and halfAngle and axis
112
111
/// are `nan`.
113
- /// - If the quaternion is non-finite, length is `.infinity` and argument and
112
+ /// - If the quaternion is non-finite, length is `.infinity` and halfAngle and
114
113
/// axis are `nan`.
115
- /// - For any length other than `.zero` or `.infinity`, if argument is zero,
114
+ /// - For any length other than `.zero` or `.infinity`, if halfAngle is zero,
116
115
/// axis is `nan`.
117
116
///
118
117
/// See also `.magnitude`, `.length`, `.lengthSquared` and
119
- /// `init(length:argument :axis:)`.
118
+ /// `init(length:halfAngle :axis:)`.
120
119
///
121
120
/// [wiki]: https://en.wikipedia.org/wiki/Polar_decomposition#Quaternion_polar_decomposition
122
- public var polar : ( length: RealType , argument: RealType , axis: SIMD3 < RealType > ) {
123
- ( length, argument, axis)
121
+ public var polar : (
122
+ length: RealType ,
123
+ halfAngle: RealType ,
124
+ axis: SIMD3 < RealType >
125
+ ) {
126
+ ( length, halfAngle, axis)
124
127
}
125
128
126
129
/// Creates a new quaternion from given half rotation angle about given
127
130
/// rotation axis.
128
131
///
129
132
/// The angle-axis values are transformed using the following equation:
130
133
///
131
- /// Q = (cos(argument ), unitAxis * sin(argument ))
134
+ /// Q = (cos(halfAngle ), unitAxis * sin(halfAngle ))
132
135
///
133
136
/// - Parameters:
134
- /// - argument : The half rotation angle
137
+ /// - halfAngle : The half rotation angle
135
138
/// - unitAxis: The rotation axis of unit length
136
139
@usableFromInline @inline ( __always)
137
- internal init ( argument : RealType , unitAxis: SIMD3 < RealType > ) {
138
- self . init ( real: . cos( argument ) , imaginary: unitAxis * . sin( argument ) )
140
+ internal init ( halfAngle : RealType , unitAxis: SIMD3 < RealType > ) {
141
+ self . init ( real: . cos( halfAngle ) , imaginary: unitAxis * . sin( halfAngle ) )
139
142
}
140
143
141
144
/// Creates a quaternion specified with [polar coordinates][wiki].
142
145
///
143
- /// This initializer reads given `length`, `argument ` and `axis` values and
146
+ /// This initializer reads given `length`, `halfAngle ` and `axis` values and
144
147
/// creates a quaternion of equal rotation properties and specified *length*
145
148
/// using the following equation:
146
149
///
147
- /// Q = (cos(argument ), axis * sin(argument )) * length
150
+ /// Q = (cos(halfAngle ), axis * sin(halfAngle )) * length
148
151
///
149
152
/// Edge cases:
150
153
/// - Negative lengths are interpreted as reflecting the point through the
151
154
/// origin, i.e.:
152
155
/// ```
153
- /// Quaternion(length: -r, argument : θ, axis: axis) == -Quaternion(length: r, argument : θ, axis: axis)
156
+ /// Quaternion(length: -r, halfAngle : θ, axis: axis) == -Quaternion(length: r, halfAngle : θ, axis: axis)
154
157
/// ```
155
158
/// - For any `θ` and any `axis`, even `.infinity` or `.nan`:
156
159
/// ```
157
- /// Quaternion(length: .zero, argument : θ, axis: axis) == .zero
160
+ /// Quaternion(length: .zero, halfAngle : θ, axis: axis) == .zero
158
161
/// ```
159
162
/// - For any `θ` and any `axis`, even `.infinity` or `.nan`:
160
163
/// ```
161
- /// Quaternion(length: .infinity, argument : θ, axis: axis) == .infinity
164
+ /// Quaternion(length: .infinity, halfAngle : θ, axis: axis) == .infinity
162
165
/// ```
163
166
/// - Otherwise, `θ` must be finite, or a precondition failure occurs and
164
167
/// `axis` must be of unit length, or an assertion failure occurs.
@@ -167,27 +170,30 @@ extension Quaternion {
167
170
///
168
171
/// [wiki]: https://en.wikipedia.org/wiki/Polar_decomposition#Quaternion_polar_decomposition
169
172
@inlinable
170
- public init ( length: RealType , argument : RealType , axis: SIMD3 < RealType > ) {
173
+ public init ( length: RealType , halfAngle : RealType , axis: SIMD3 < RealType > ) {
171
174
guard !length. isZero, length. isFinite else {
172
175
self = Quaternion ( length)
173
176
return
174
177
}
175
178
176
179
// Length is finite and non-zero, therefore
177
- // 1. `argument ` must be finite or a precondition failure needs to occur; as
178
- // this is not representable.
180
+ // 1. `halfAngle ` must be finite or a precondition failure needs to occur;
181
+ // as this is not representable.
179
182
// 2. `axis` must be of unit length or an assertion failure occurs; while
180
183
// "wrong" by definition, it is representable.
181
184
precondition (
182
- argument . isFinite,
183
- " Either argument must be finite, or length must be zero or infinite. "
185
+ halfAngle . isFinite,
186
+ " Either halfAngle must be finite, or length must be zero or infinite. "
184
187
)
185
188
assert (
186
189
// TODO: Replace with `approximateEquality()`
187
190
abs ( . sqrt( axis. lengthSquared) - 1 ) < max ( . sqrt( axis. lengthSquared) , 1 ) * RealType. ulpOfOne. squareRoot ( ) ,
188
191
" Given axis must be of unit length. "
189
192
)
190
193
191
- self = Quaternion ( argument: argument, unitAxis: axis) . multiplied ( by: length)
194
+ self = Quaternion (
195
+ halfAngle: halfAngle,
196
+ unitAxis: axis
197
+ ) . multiplied ( by: length)
192
198
}
193
199
}
0 commit comments