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/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