unit_quaternion 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -1
- data/CHANGELOG +2 -0
- data/lib/quaternion.rb +12 -12
- data/lib/unit_quaternion/version.rb +2 -2
- data/lib/unit_quaternion.rb +3 -19
- data/unit_quaternion.gemspec +1 -1
- metadata +2 -1
data/.gitignore
CHANGED
data/CHANGELOG
ADDED
data/lib/quaternion.rb
CHANGED
@@ -39,51 +39,51 @@ class Quaternion
|
|
39
39
|
return @beta0, @beta_s
|
40
40
|
end
|
41
41
|
|
42
|
-
# Returns the magnitude of the quaternion
|
42
|
+
# Returns the magnitude of the quaternion.
|
43
43
|
def norm
|
44
44
|
return Math.sqrt(@beta0**2 + @beta_s.norm()**2)
|
45
45
|
end
|
46
46
|
|
47
|
-
# Returns the conjugate of the quaternion
|
47
|
+
# Returns the conjugate of the quaternion.
|
48
48
|
def conjugate
|
49
49
|
return Quaternion.new(@beta0, *(-1*@beta_s))
|
50
50
|
end
|
51
51
|
|
52
|
-
# Returns the multiplicative inverse of the quaterion
|
52
|
+
# Returns the multiplicative inverse of the quaterion.
|
53
53
|
def inverse
|
54
54
|
return self.conjugate() / self.norm() ** 2
|
55
55
|
end
|
56
56
|
|
57
57
|
# Returns a normalized quaternion. q.normalized() is equivalent to
|
58
|
-
# q/q.norm()
|
58
|
+
# q/q.norm().
|
59
59
|
def normalized
|
60
60
|
return self / norm()
|
61
61
|
end
|
62
62
|
|
63
|
-
# Returns the sum of two quaternions
|
63
|
+
# Returns the sum of two quaternions.
|
64
64
|
def +(q)
|
65
65
|
beta0, beta_s = q.get()
|
66
66
|
return Quaternion.new(@beta0 + beta0, *(@beta_s + beta_s))
|
67
67
|
end
|
68
68
|
|
69
|
-
# Returns the difference of two quaternions
|
69
|
+
# Returns the difference of two quaternions.
|
70
70
|
def -(q)
|
71
71
|
beta0, beta_s = q.get()
|
72
72
|
return Quaternion.new(@beta0 - beta0, *(@beta_s - beta_s))
|
73
73
|
end
|
74
74
|
|
75
|
-
# Returns the additive inverse of the quaternion
|
75
|
+
# Returns the additive inverse of the quaternion.
|
76
76
|
def -@
|
77
77
|
Quaternion.new(-@beta0, -@beta_s[0], -@beta_s[1], -@beta_s[2])
|
78
78
|
end
|
79
79
|
|
80
|
-
# Returns the result of dividing the quaternion by a scalar
|
80
|
+
# Returns the result of dividing the quaternion by a scalar.
|
81
81
|
def /(s)
|
82
82
|
return Quaternion.new(@beta0 / s, *(@beta_s / s))
|
83
83
|
end
|
84
84
|
|
85
85
|
# Returns the result of multiplying the quaternion by a scalar or
|
86
|
-
# another quaternion
|
86
|
+
# another quaternion.
|
87
87
|
def *(q)
|
88
88
|
if q.is_a?(Numeric)
|
89
89
|
return Quaternion.new(@beta0 * q, *(@beta_s * q))
|
@@ -98,7 +98,7 @@ class Quaternion
|
|
98
98
|
end
|
99
99
|
|
100
100
|
# Returns true if two quaternions are equal (meaning that their
|
101
|
-
# corresponding entries are equal to each other) and false otherwise
|
101
|
+
# corresponding entries are equal to each other) and false otherwise.
|
102
102
|
def ==(q)
|
103
103
|
if get() == q.get()
|
104
104
|
return true
|
@@ -107,7 +107,7 @@ class Quaternion
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
# Returns the string representation of the quaternion
|
110
|
+
# Returns the string representation of the quaternion.
|
111
111
|
def to_s
|
112
112
|
return "(" + @beta0.to_s + ", " + @beta_s.to_s + ")"
|
113
113
|
end
|
@@ -118,7 +118,7 @@ class Quaternion
|
|
118
118
|
|
119
119
|
private
|
120
120
|
def cross_product(v1, v2)
|
121
|
-
# returns the cross product of vectors v1 and v2
|
121
|
+
# returns the cross product of vectors v1 and v2.
|
122
122
|
return Vector[ v1[1]*v2[2] - v1[2]*v2[1],
|
123
123
|
v1[2]*v2[0] - v1[0]*v2[2],
|
124
124
|
v1[0]*v2[1] - v1[1]*v2[0] ]
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
class UnitQuaternion
|
2
|
+
VERSION = "0.0.4"
|
3
3
|
end
|
data/lib/unit_quaternion.rb
CHANGED
@@ -32,8 +32,6 @@ class UnitQuaternion < Quaternion
|
|
32
32
|
# +angle+:: A scalar representing the angle of the rotation (in radians)
|
33
33
|
# +axis+:: A vector representing the axis of rotation (need not be a unit vector)
|
34
34
|
def self.fromAngleAxis(angle, axis)
|
35
|
-
# intializes a quaternion from the angle-axis representation of a
|
36
|
-
# rotation
|
37
35
|
q = UnitQuaternion.new()
|
38
36
|
q.setAngleAxis(angle, axis)
|
39
37
|
return q
|
@@ -52,7 +50,7 @@ class UnitQuaternion < Quaternion
|
|
52
50
|
return q
|
53
51
|
end
|
54
52
|
|
55
|
-
# Initializes a quaternion from a rotation matrix
|
53
|
+
# Initializes a quaternion from a rotation matrix.
|
56
54
|
#
|
57
55
|
# Params:
|
58
56
|
# +mat+:: A 3x3 orthonormal matrix.
|
@@ -71,7 +69,6 @@ class UnitQuaternion < Quaternion
|
|
71
69
|
# +y+:: the j-component
|
72
70
|
# +z+:: the k-component
|
73
71
|
def set(w, x, y, z)
|
74
|
-
# sets the values of the quaternion
|
75
72
|
super(w, x, y, z)
|
76
73
|
@beta0, @beta_s = normalized().get()
|
77
74
|
end
|
@@ -84,8 +81,6 @@ class UnitQuaternion < Quaternion
|
|
84
81
|
# +angle+:: A scalar representing the angle of the rotation (in radians)
|
85
82
|
# +axis+:: A vector representing the axis of rotation (need not be a unit vector)
|
86
83
|
def setAngleAxis(angle, axis)
|
87
|
-
# sets the quaternion based on the angle-axis representation of a
|
88
|
-
# rotation
|
89
84
|
if axis == Vector[0,0,0]
|
90
85
|
raise(ArgumentError, "Axis must not be the zero vector")
|
91
86
|
end
|
@@ -107,8 +102,6 @@ class UnitQuaternion < Quaternion
|
|
107
102
|
# +angle+:: A scalar representing the angle of rotation (in radians)
|
108
103
|
# +axis+:: A unit vector representing the axis of rotation
|
109
104
|
def getAngleAxis
|
110
|
-
# return the angle-axis representation of the rotation contained in
|
111
|
-
# this quaternion
|
112
105
|
angle = 2*Math.acos(@beta0)
|
113
106
|
|
114
107
|
# if sin(theta/2) = 0, then theta = 2*n*PI, where n is any integer,
|
@@ -166,14 +159,6 @@ class UnitQuaternion < Quaternion
|
|
166
159
|
# +theta2+:: The angle of rotation about the second axis
|
167
160
|
# +theta3+:: The angle of rotation about the third axis
|
168
161
|
def getEuler(axes)
|
169
|
-
# Returns the Euler angles about the specified axes. The axes should
|
170
|
-
# be specified as a string, and can be any permutation (with
|
171
|
-
# replacement) of 'X', 'Y', and 'Z', as long as no letter is adjacent
|
172
|
-
# to itself (for example, 'XYX' is valid, but 'XXY' is not).
|
173
|
-
# If the axes are uppercase, this function returns the angles about
|
174
|
-
# the global axes. If they are lowercase, this function returns the
|
175
|
-
# angles about the body-fixed axes.
|
176
|
-
#
|
177
162
|
# This method implements Shoemake's algorithm for finding the Euler
|
178
163
|
# angles from a rotation matrix, found in Graphics Gems IV (pg. 222).
|
179
164
|
|
@@ -244,7 +229,7 @@ class UnitQuaternion < Quaternion
|
|
244
229
|
return theta1, theta2, theta3
|
245
230
|
end
|
246
231
|
|
247
|
-
# Sets the values of the quaternion from a rotation matrix
|
232
|
+
# Sets the values of the quaternion from a rotation matrix.
|
248
233
|
#
|
249
234
|
# Params:
|
250
235
|
# +mat+:: A 3x3 orthonormal matrix.
|
@@ -263,7 +248,6 @@ class UnitQuaternion < Quaternion
|
|
263
248
|
|
264
249
|
# Returns the rotation matrix corresponding to this quaternion.
|
265
250
|
def getRotationMatrix
|
266
|
-
# returns the rotation matrix corresponding to this quaternion
|
267
251
|
return Matrix[ [ @beta0**2 + @beta_s[0]**2 - @beta_s[1]**2 - @beta_s[2]**2,
|
268
252
|
2*(@beta_s[0]*@beta_s[1] - @beta0*@beta_s[2]),
|
269
253
|
2*(@beta_s[0]*@beta_s[2] + @beta0*@beta_s[1]) ],
|
@@ -284,7 +268,7 @@ class UnitQuaternion < Quaternion
|
|
284
268
|
return getRotationMatrix() * vec
|
285
269
|
end
|
286
270
|
|
287
|
-
# Returns the inverse of the quaternion
|
271
|
+
# Returns the inverse of the quaternion.
|
288
272
|
def inverse
|
289
273
|
result = UnitQuaternion.new
|
290
274
|
result.set(@beta0, *(-1*@beta_s))
|
data/unit_quaternion.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'unit_quaternion/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "unit_quaternion"
|
8
|
-
spec.version =
|
8
|
+
spec.version = UnitQuaternion::VERSION
|
9
9
|
spec.authors = ["Cory Crean"]
|
10
10
|
spec.email = ["cory.crean@gmail.com"]
|
11
11
|
spec.description = %q{Provides a general Quaternion class, and UnitQuaternion class to represent rotations}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unit_quaternion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -84,6 +84,7 @@ extensions: []
|
|
84
84
|
extra_rdoc_files: []
|
85
85
|
files:
|
86
86
|
- .gitignore
|
87
|
+
- CHANGELOG
|
87
88
|
- Gemfile
|
88
89
|
- LICENSE.txt
|
89
90
|
- README.md
|