geo3d 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/lib/geo3d/version.rb +1 -1
- data/lib/quaternion.rb +112 -13
- data/lib/utils.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8af038ca077d7a6bdfd933b9486cf4a63ab8a73f
|
4
|
+
data.tar.gz: 75bb46be5985112547d52bcdfb06046c651ba2af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81c47c990a4c186edb1c07d632f1c287d3854686ab589e071f6a496733d08b8c04929989ee473c7a08d91b5451e6cc1583311604cf87e4fb859a998b7c31b216
|
7
|
+
data.tar.gz: 2799ed1ff5754f41b74ce781105c68a5ba864661346d36967012be1ca5cdbeebf8411b726713ea0ed95e3d23b4aaf845788de786c892157a13f64b1007c8a67f
|
data/README.md
CHANGED
@@ -167,10 +167,38 @@ Misc constructors
|
|
167
167
|
Geo3d::Matrix.reflection reflection_plane #returns a reflection matrix where reflection_plane is a Geo3d::Vector that corresponds to the normal of the plane
|
168
168
|
Geo3d::Matrix.shadow light_position, plane #returns a shadow matrix
|
169
169
|
```
|
170
|
+
Matrix Decomposition
|
171
|
+
```
|
172
|
+
matrix.scaling_component
|
173
|
+
matrix.translation_component
|
174
|
+
matrix.rotation_component
|
175
|
+
```
|
170
176
|
|
171
177
|
|
172
178
|
## Quaternion
|
173
179
|
|
180
|
+
A mathematical construct to represent rotations in 3d space.
|
181
|
+
|
182
|
+
Quaternion Multiplication
|
183
|
+
```
|
184
|
+
quat_a * quat_b
|
185
|
+
```
|
186
|
+
Getting axis and angle
|
187
|
+
```
|
188
|
+
quat.axis
|
189
|
+
quat.angle
|
190
|
+
```
|
191
|
+
Converting to a matrix
|
192
|
+
```
|
193
|
+
quat.to_matrix
|
194
|
+
```
|
195
|
+
Constructors
|
196
|
+
```
|
197
|
+
Geo3d::Quaternion.from_axis rotation_axis, radians #returns a quaternion from an axis and angle
|
198
|
+
Geo3d::Quaternion.from_matrix m #returns a quaternion from a rotation matrix
|
199
|
+
|
200
|
+
```
|
201
|
+
|
174
202
|
Documentation coming soon!
|
175
203
|
|
176
204
|
|
data/lib/geo3d/version.rb
CHANGED
data/lib/quaternion.rb
CHANGED
@@ -2,8 +2,15 @@ module Geo3d
|
|
2
2
|
class Quaternion
|
3
3
|
attr_reader :x, :y, :z, :w
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
@x =
|
5
|
+
def initialize *args
|
6
|
+
@x = 0.0
|
7
|
+
@y = 0.0
|
8
|
+
@z = 0.0
|
9
|
+
@w = 0.0
|
10
|
+
@x = args[0].to_f if args.size > 0
|
11
|
+
@y = args[1].to_f if args.size > 1
|
12
|
+
@z = args[2].to_f if args.size > 2
|
13
|
+
@w = args[3].to_f if args.size > 3
|
7
14
|
end
|
8
15
|
|
9
16
|
def x= v
|
@@ -22,6 +29,22 @@ module Geo3d
|
|
22
29
|
@w = v.to_f
|
23
30
|
end
|
24
31
|
|
32
|
+
def +@
|
33
|
+
self.class.new x, y, z, w
|
34
|
+
end
|
35
|
+
|
36
|
+
def -@
|
37
|
+
self.class.new -x, -y, -z, -w
|
38
|
+
end
|
39
|
+
|
40
|
+
def == q
|
41
|
+
Geo3d::Utils.float_cmp(x, q.x) && Geo3d::Utils.float_cmp(y, q.y) && Geo3d::Utils.float_cmp(z, q.z) && Geo3d::Utils.float_cmp(w, q.w)
|
42
|
+
end
|
43
|
+
|
44
|
+
def != vec
|
45
|
+
!(self == vec)
|
46
|
+
end
|
47
|
+
|
25
48
|
def self.from_axis rotation_axis, radians = 0
|
26
49
|
normalized_rotation_axis = rotation_axis.normalize
|
27
50
|
#const float radians = GeoConvertToRadians( degrees );
|
@@ -34,6 +57,10 @@ module Geo3d
|
|
34
57
|
q
|
35
58
|
end
|
36
59
|
|
60
|
+
def self.from_axis_degrees rotation_axis, degrees = 0
|
61
|
+
from_axis rotation_axis, Geo3d::Utils.to_radians(degrees)
|
62
|
+
end
|
63
|
+
|
37
64
|
def self.from_matrix pm
|
38
65
|
pout = self.new
|
39
66
|
|
@@ -80,13 +107,30 @@ module Geo3d
|
|
80
107
|
pout
|
81
108
|
end
|
82
109
|
|
83
|
-
def
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
110
|
+
def + quat
|
111
|
+
self.class.new x + quat.x, y + quat.y, z + quat.z, w + quat.w
|
112
|
+
end
|
113
|
+
|
114
|
+
def - quat
|
115
|
+
self.class.new x - quat.x, y - quat.y, z - quat.z, w - quat.w
|
116
|
+
end
|
117
|
+
|
118
|
+
def * v
|
119
|
+
if Quaternion == v.class
|
120
|
+
quat = v
|
121
|
+
out = self.class.new
|
122
|
+
out.w = w * quat.w - x * quat.x - y * quat.y - z * quat.z
|
123
|
+
out.x = w * quat.x + x * quat.w + y * quat.z - z * quat.y
|
124
|
+
out.y = w * quat.y - x * quat.z + y * quat.w + z * quat.x
|
125
|
+
out.z = w * quat.z + x * quat.y - y * quat.x + z * quat.w
|
126
|
+
out
|
127
|
+
else
|
128
|
+
self.class.new x*v, y*v, z*v, w*v
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def / v
|
133
|
+
self.class.new x/v, y/v, z/v, w/v
|
90
134
|
end
|
91
135
|
|
92
136
|
def to_matrix
|
@@ -105,15 +149,70 @@ module Geo3d
|
|
105
149
|
end
|
106
150
|
|
107
151
|
def axis
|
152
|
+
q = normalize
|
108
153
|
v = Vector.new
|
109
|
-
v.x = x / Math.sqrt(1-w*w)
|
110
|
-
v.y = y / Math.sqrt(1-w*w)
|
111
|
-
v.z = z / Math.sqrt(1-w*w)
|
154
|
+
v.x = q.x / Math.sqrt(1-q.w*q.w)
|
155
|
+
v.y = q.y / Math.sqrt(1-q.w*q.w)
|
156
|
+
v.z = q.z / Math.sqrt(1-q.w*q.w)
|
112
157
|
v
|
113
158
|
end
|
114
159
|
|
115
160
|
def angle
|
116
|
-
|
161
|
+
q = normalize
|
162
|
+
Math.acos(q.w) * 2.0
|
163
|
+
end
|
164
|
+
|
165
|
+
def angle_degrees
|
166
|
+
Geo3d::Utils.to_degrees angle
|
167
|
+
end
|
168
|
+
|
169
|
+
def length_squared
|
170
|
+
dot self
|
171
|
+
end
|
172
|
+
|
173
|
+
def length
|
174
|
+
Math.sqrt length_squared
|
175
|
+
end
|
176
|
+
|
177
|
+
def dot quat
|
178
|
+
x * quat.x + y * quat.y + z * quat.z + w * quat.w
|
179
|
+
end
|
180
|
+
|
181
|
+
def normalize!
|
182
|
+
len = length
|
183
|
+
if length > 0
|
184
|
+
@x /= len
|
185
|
+
@y /= len
|
186
|
+
@z /= len
|
187
|
+
@w /= len
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def normalize
|
192
|
+
q = self.class.new x, y, z, w
|
193
|
+
q.normalize!
|
194
|
+
q
|
195
|
+
end
|
196
|
+
|
197
|
+
def conjugate
|
198
|
+
self.class.new -x, -y, -z, w
|
199
|
+
end
|
200
|
+
|
201
|
+
def inverse
|
202
|
+
norm = length_squared
|
203
|
+
if norm.zero?
|
204
|
+
self.class.new 0, 0, 0, 0
|
205
|
+
else
|
206
|
+
conjugate / norm
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def identity?
|
211
|
+
self == self.class.identity
|
212
|
+
end
|
213
|
+
|
214
|
+
def self.identity
|
215
|
+
self.new 0, 0, 0, 1
|
117
216
|
end
|
118
217
|
end
|
119
218
|
end
|
data/lib/utils.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geo3d
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Misha Conway
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|