gmath3D 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -5
- data/Gemfile +5 -11
- data/LICENSE.txt +20 -20
- data/README.rdoc +19 -19
- data/Rakefile +45 -45
- data/VERSION +1 -1
- data/gmath3D.gemspec +79 -80
- data/lib/box.rb +145 -145
- data/lib/ellipse.rb +11 -11
- data/lib/ext.rb +82 -82
- data/lib/finite_line.rb +244 -244
- data/lib/geom.rb +20 -20
- data/lib/gmath3D.rb +22 -22
- data/lib/line.rb +122 -122
- data/lib/plane.rb +131 -131
- data/lib/polyline.rb +73 -73
- data/lib/quat.rb +170 -170
- data/lib/rectangle.rb +155 -155
- data/lib/tri_mesh.rb +258 -258
- data/lib/triangle.rb +281 -281
- data/lib/util.rb +36 -23
- data/lib/vector3.rb +227 -227
- data/test/helper.rb +15 -15
- data/test/test_box.rb +167 -167
- data/test/test_ellipse.rb +55 -55
- data/test/test_finite_line.rb +306 -306
- data/test/test_geom.rb +17 -17
- data/test/test_line.rb +146 -146
- data/test/test_matrix_util.rb +84 -84
- data/test/test_plane.rb +200 -200
- data/test/test_polyline.rb +93 -93
- data/test/test_quat.rb +144 -144
- data/test/test_rectangle.rb +184 -184
- data/test/test_tri_mesh.rb +186 -186
- data/test/test_triangle.rb +318 -318
- data/test/test_util.rb +88 -57
- data/test/test_vector3.rb +439 -439
- metadata +8 -11
- data/Gemfile.lock +0 -16
data/lib/ellipse.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'gmath3D'
|
2
|
-
|
3
|
-
module GMath3D
|
4
|
-
#
|
5
|
-
#
|
6
|
-
class Ellipse < Geom
|
7
|
-
def initialize(origin = Vector3.new(), axis1 = Vector3.new(1,0,0), axis2 = Vector3.new(0,1,0))
|
8
|
-
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
require 'gmath3D'
|
2
|
+
|
3
|
+
module GMath3D
|
4
|
+
#
|
5
|
+
#
|
6
|
+
class Ellipse < Geom
|
7
|
+
def initialize(origin = Vector3.new(), axis1 = Vector3.new(1,0,0), axis2 = Vector3.new(0,1,0))
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/ext.rb
CHANGED
@@ -1,82 +1,82 @@
|
|
1
|
-
require 'gmath3D'
|
2
|
-
require 'matrix'
|
3
|
-
|
4
|
-
module GMath3D
|
5
|
-
class ::Matrix
|
6
|
-
def self.from_axis(axis, angle)
|
7
|
-
Util3D::check_arg_type(Vector3, axis)
|
8
|
-
Util3D::check_arg_type(Numeric, angle)
|
9
|
-
|
10
|
-
return Matrix[
|
11
|
-
[axis.x*axis.x*(1 - Math.cos(angle)) + Math.cos(angle),
|
12
|
-
axis.x*axis.y*(1 - Math.cos(angle)) + axis.z*Math.sin(angle),
|
13
|
-
axis.x*axis.z*(1 - Math.cos(angle)) - axis.y*Math.sin(angle)],
|
14
|
-
[axis.x*axis.y*(1 - Math.cos(angle)) - axis.z*Math.sin(angle),
|
15
|
-
axis.y*axis.y*(1 - Math.cos(angle)) + Math.cos(angle),
|
16
|
-
axis.y*axis.z*(1 - Math.cos(angle)) + axis.x*Math.sin(angle)],
|
17
|
-
[axis.x*axis.z*(1 - Math.cos(angle)) + axis.y*Math.sin(angle),
|
18
|
-
axis.y*axis.z*(1 - Math.cos(angle)) - axis.x*Math.sin(angle),
|
19
|
-
axis.z*axis.z*(1 - Math.cos(angle)) + Math.cos(angle)]]
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.from_quat(quat)
|
23
|
-
Util3D::check_arg_type(Quat, quat)
|
24
|
-
qw = quat.w
|
25
|
-
qx = quat.x
|
26
|
-
qy = quat.y
|
27
|
-
qz = quat.z
|
28
|
-
|
29
|
-
x2 = 2.0 * qx * qx;
|
30
|
-
y2 = 2.0 * qy * qy;
|
31
|
-
z2 = 2.0 * qz * qz;
|
32
|
-
xy = 2.0 * qx * qy;
|
33
|
-
yz = 2.0 * qy * qz;
|
34
|
-
zx = 2.0 * qz * qx;
|
35
|
-
wx = 2.0 * qw * qx;
|
36
|
-
wy = 2.0 * qw * qy;
|
37
|
-
wz = 2.0 * qw * qz;
|
38
|
-
|
39
|
-
return Matrix[
|
40
|
-
[ 1.0 - y2 - z2, xy + wz, zx - wy],
|
41
|
-
[ xy - wz, 1.0 - z2 - x2, yz + wx],
|
42
|
-
[ zx + wy, yz - wx, 1.0 - x2 - y2]]
|
43
|
-
end
|
44
|
-
|
45
|
-
alias_method :multi_inner, :* # hold original multiply processing
|
46
|
-
def multi_new(rhs)
|
47
|
-
if(rhs.kind_of?(Vector3))
|
48
|
-
ans = self.multi_inner(rhs.to_column_vector)
|
49
|
-
return Vector3.new(ans[0,0], ans[1,0], ans[2,0])
|
50
|
-
end
|
51
|
-
multi_inner(rhs)
|
52
|
-
end
|
53
|
-
alias_method :*, :multi_new # overwrite new multiply processing
|
54
|
-
end
|
55
|
-
|
56
|
-
class ::Array
|
57
|
-
def sum
|
58
|
-
s, n = self.sum_with_number
|
59
|
-
return s
|
60
|
-
end
|
61
|
-
def avg
|
62
|
-
s, n = self.sum_with_number
|
63
|
-
return s / n
|
64
|
-
end
|
65
|
-
|
66
|
-
def sum_with_number
|
67
|
-
return nil, 0 if(self.size <= 0)
|
68
|
-
s = nil
|
69
|
-
n = 0
|
70
|
-
self.each do |v|
|
71
|
-
next if v.nil?
|
72
|
-
if(s==nil)
|
73
|
-
s = v
|
74
|
-
else
|
75
|
-
s += v
|
76
|
-
end
|
77
|
-
n += 1
|
78
|
-
end
|
79
|
-
return s, n
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
1
|
+
require 'gmath3D'
|
2
|
+
require 'matrix'
|
3
|
+
|
4
|
+
module GMath3D
|
5
|
+
class ::Matrix
|
6
|
+
def self.from_axis(axis, angle)
|
7
|
+
Util3D::check_arg_type(Vector3, axis)
|
8
|
+
Util3D::check_arg_type(Numeric, angle)
|
9
|
+
|
10
|
+
return Matrix[
|
11
|
+
[axis.x*axis.x*(1 - Math.cos(angle)) + Math.cos(angle),
|
12
|
+
axis.x*axis.y*(1 - Math.cos(angle)) + axis.z*Math.sin(angle),
|
13
|
+
axis.x*axis.z*(1 - Math.cos(angle)) - axis.y*Math.sin(angle)],
|
14
|
+
[axis.x*axis.y*(1 - Math.cos(angle)) - axis.z*Math.sin(angle),
|
15
|
+
axis.y*axis.y*(1 - Math.cos(angle)) + Math.cos(angle),
|
16
|
+
axis.y*axis.z*(1 - Math.cos(angle)) + axis.x*Math.sin(angle)],
|
17
|
+
[axis.x*axis.z*(1 - Math.cos(angle)) + axis.y*Math.sin(angle),
|
18
|
+
axis.y*axis.z*(1 - Math.cos(angle)) - axis.x*Math.sin(angle),
|
19
|
+
axis.z*axis.z*(1 - Math.cos(angle)) + Math.cos(angle)]]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.from_quat(quat)
|
23
|
+
Util3D::check_arg_type(Quat, quat)
|
24
|
+
qw = quat.w
|
25
|
+
qx = quat.x
|
26
|
+
qy = quat.y
|
27
|
+
qz = quat.z
|
28
|
+
|
29
|
+
x2 = 2.0 * qx * qx;
|
30
|
+
y2 = 2.0 * qy * qy;
|
31
|
+
z2 = 2.0 * qz * qz;
|
32
|
+
xy = 2.0 * qx * qy;
|
33
|
+
yz = 2.0 * qy * qz;
|
34
|
+
zx = 2.0 * qz * qx;
|
35
|
+
wx = 2.0 * qw * qx;
|
36
|
+
wy = 2.0 * qw * qy;
|
37
|
+
wz = 2.0 * qw * qz;
|
38
|
+
|
39
|
+
return Matrix[
|
40
|
+
[ 1.0 - y2 - z2, xy + wz, zx - wy],
|
41
|
+
[ xy - wz, 1.0 - z2 - x2, yz + wx],
|
42
|
+
[ zx + wy, yz - wx, 1.0 - x2 - y2]]
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method :multi_inner, :* # hold original multiply processing
|
46
|
+
def multi_new(rhs)
|
47
|
+
if(rhs.kind_of?(Vector3))
|
48
|
+
ans = self.multi_inner(rhs.to_column_vector)
|
49
|
+
return Vector3.new(ans[0,0], ans[1,0], ans[2,0])
|
50
|
+
end
|
51
|
+
multi_inner(rhs)
|
52
|
+
end
|
53
|
+
alias_method :*, :multi_new # overwrite new multiply processing
|
54
|
+
end
|
55
|
+
|
56
|
+
class ::Array
|
57
|
+
def sum
|
58
|
+
s, n = self.sum_with_number
|
59
|
+
return s
|
60
|
+
end
|
61
|
+
def avg
|
62
|
+
s, n = self.sum_with_number
|
63
|
+
return s / n
|
64
|
+
end
|
65
|
+
|
66
|
+
def sum_with_number
|
67
|
+
return nil, 0 if(self.size <= 0)
|
68
|
+
s = nil
|
69
|
+
n = 0
|
70
|
+
self.each do |v|
|
71
|
+
next if v.nil?
|
72
|
+
if(s==nil)
|
73
|
+
s = v
|
74
|
+
else
|
75
|
+
s += v
|
76
|
+
end
|
77
|
+
n += 1
|
78
|
+
end
|
79
|
+
return s, n
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|