eigen 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +14 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +18 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/eigen.gemspec +27 -0
- data/ext/eigen/eigen.cpp +1170 -0
- data/ext/eigen/extconf.rb +10 -0
- data/lib/eigen.rb +15 -0
- data/lib/eigen/affine3.rb +35 -0
- data/lib/eigen/angle_axis.rb +90 -0
- data/lib/eigen/isometry3.rb +36 -0
- data/lib/eigen/matrix4.rb +96 -0
- data/lib/eigen/matrixx.rb +105 -0
- data/lib/eigen/quaternion.rb +253 -0
- data/lib/eigen/vector3.rb +178 -0
- data/lib/eigen/vectorx.rb +54 -0
- data/lib/eigen/version.rb +3 -0
- metadata +144 -0
@@ -0,0 +1,178 @@
|
|
1
|
+
module Eigen
|
2
|
+
# 3-dimensional vector
|
3
|
+
class Vector3
|
4
|
+
# Returns a vector with all values set to Base.unset
|
5
|
+
def self.Unset
|
6
|
+
return Vector3.new(Base.unset, Base.unset, Base.unset)
|
7
|
+
end
|
8
|
+
|
9
|
+
def dup
|
10
|
+
Vector3.new(x, y, z)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the [x, y, z] tuple
|
14
|
+
def to_a; [x, y, z] end
|
15
|
+
|
16
|
+
# Returns the (1, 0, 0) unit vector
|
17
|
+
def self.UnitX()
|
18
|
+
return Vector3.new(1, 0, 0)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns the (0, 1, 0) unit vector
|
22
|
+
def self.UnitY()
|
23
|
+
return Vector3.new(0, 1, 0)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the (0, 0, 1) unit vector
|
27
|
+
def self.UnitZ()
|
28
|
+
return Vector3.new(0, 0, 1)
|
29
|
+
end
|
30
|
+
|
31
|
+
# returns the (0, 0, 0) vector
|
32
|
+
def self.Zero()
|
33
|
+
return Vector3.new(0, 0, 0)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the angle formed by +self+ and +v+, oriented from +self+ to
|
37
|
+
# +v+
|
38
|
+
def angle_to(v)
|
39
|
+
ret = Math.atan2(v.y, v.x) - Math.atan2(y, x)
|
40
|
+
if ret > Math::PI
|
41
|
+
ret -= 2*Math::PI
|
42
|
+
end
|
43
|
+
if ret < -Math::PI
|
44
|
+
ret += 2*Math::PI
|
45
|
+
end
|
46
|
+
ret
|
47
|
+
end
|
48
|
+
|
49
|
+
# Tests for equality
|
50
|
+
#
|
51
|
+
# Since Vector3 stores the coordinates as floating-point values, this is
|
52
|
+
# a bad test. Use
|
53
|
+
#
|
54
|
+
# q.approx?(other_q, tolerance)
|
55
|
+
#
|
56
|
+
# instead
|
57
|
+
def ==(v)
|
58
|
+
v.kind_of?(self.class) &&
|
59
|
+
__equal__(v)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Support for Marshal
|
63
|
+
def _dump(level) # :nodoc:
|
64
|
+
Marshal.dump(to_a)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Support for Marshal
|
68
|
+
def self._load(coordinates) # :nodoc:
|
69
|
+
new(*Marshal.load(coordinates))
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_s # :nodoc:
|
73
|
+
"Vector3(#{x}, #{y}, #{z})"
|
74
|
+
end
|
75
|
+
|
76
|
+
def data
|
77
|
+
[x, y, z]
|
78
|
+
end
|
79
|
+
|
80
|
+
def data=(value)
|
81
|
+
self.x,self.y,self.z = value
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# :method: ==
|
86
|
+
|
87
|
+
##
|
88
|
+
# :method: []
|
89
|
+
#
|
90
|
+
# Returns the i-th coordinate
|
91
|
+
|
92
|
+
##
|
93
|
+
# :method: []=
|
94
|
+
#
|
95
|
+
# Sets the i-th coordinate
|
96
|
+
|
97
|
+
##
|
98
|
+
# :method: x
|
99
|
+
|
100
|
+
##
|
101
|
+
# :method: y
|
102
|
+
|
103
|
+
##
|
104
|
+
# :method: z
|
105
|
+
|
106
|
+
##
|
107
|
+
# :method: x=
|
108
|
+
|
109
|
+
##
|
110
|
+
# :method: y=
|
111
|
+
|
112
|
+
##
|
113
|
+
# :method: z=
|
114
|
+
|
115
|
+
##
|
116
|
+
# :method: +
|
117
|
+
|
118
|
+
##
|
119
|
+
# :method: -
|
120
|
+
|
121
|
+
##
|
122
|
+
# :method: -@
|
123
|
+
|
124
|
+
##
|
125
|
+
# :method: *
|
126
|
+
# :call-seq:
|
127
|
+
# a * scalar => b
|
128
|
+
#
|
129
|
+
# Returns +a+ scaled with the given scalar
|
130
|
+
|
131
|
+
##
|
132
|
+
# :method: cross
|
133
|
+
# :call-seq:
|
134
|
+
# cross(b) => c
|
135
|
+
#
|
136
|
+
# Returns the cross product of +self+ with +b+
|
137
|
+
|
138
|
+
##
|
139
|
+
# :method: norm
|
140
|
+
#
|
141
|
+
# Returns the norm of +self+
|
142
|
+
|
143
|
+
##
|
144
|
+
# :method: normalize!
|
145
|
+
#
|
146
|
+
# Makes this vector unit-length
|
147
|
+
|
148
|
+
##
|
149
|
+
# :method: normalize
|
150
|
+
#
|
151
|
+
# Returns a vector that has the same direction than +self+ but unit
|
152
|
+
# length
|
153
|
+
|
154
|
+
##
|
155
|
+
# Computes the signed angle between two vectors, using the provided
|
156
|
+
# vector as "positive" rotation direction
|
157
|
+
#
|
158
|
+
# The returned angle A is so that the rotation defined by A and axis
|
159
|
+
# will transform +self+ into +v+
|
160
|
+
def signed_angle_to(v, axis)
|
161
|
+
dot_p = self.dot(v)
|
162
|
+
dir = self.cross(v).dot(axis)
|
163
|
+
|
164
|
+
unsigned = Math.acos(dot_p / norm / v.norm)
|
165
|
+
if dir > 0
|
166
|
+
return unsigned
|
167
|
+
else
|
168
|
+
return -unsigned
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# @return [Qt::Quaternion] the Qt vector that is identical to this
|
173
|
+
# one
|
174
|
+
def to_qt
|
175
|
+
Qt::Vector3D.new(x, y, z)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Eigen
|
2
|
+
# Abritary size vector
|
3
|
+
class VectorX
|
4
|
+
def dup
|
5
|
+
VectorX.from_a(to_a)
|
6
|
+
end
|
7
|
+
|
8
|
+
# Returns the array value in a vector
|
9
|
+
def to_a()
|
10
|
+
a = []
|
11
|
+
for i in 0..size()-1
|
12
|
+
a << self[i]
|
13
|
+
end
|
14
|
+
a
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.from_a(array)
|
18
|
+
v = VectorX.new
|
19
|
+
v.from_a(array)
|
20
|
+
v
|
21
|
+
end
|
22
|
+
|
23
|
+
def from_a(array)
|
24
|
+
resize(array.size())
|
25
|
+
for i in 0..array.size()-1
|
26
|
+
self[i] = array[i]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def ==(v)
|
31
|
+
v.kind_of?(self.class) &&
|
32
|
+
__equal__(v)
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s # :nodoc:
|
36
|
+
str = "VectorX("
|
37
|
+
for i in 0..size()-1
|
38
|
+
str += "#{self[i]} "
|
39
|
+
end
|
40
|
+
str[-1] = ")"
|
41
|
+
str
|
42
|
+
end
|
43
|
+
|
44
|
+
def _dump(level) # :nodoc:
|
45
|
+
Marshal.dump(to_a)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self._load(coordinates) # :nodoc:
|
49
|
+
m = new()
|
50
|
+
m.from_a(Marshal.load(coordinates))
|
51
|
+
m
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eigen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sylvain Joyeux
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rice
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.1.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.1.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.12'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.12'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake-compiler
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: minitest
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '5.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '5.0'
|
89
|
+
description:
|
90
|
+
email:
|
91
|
+
- sylvain.joyeux@m4x.org
|
92
|
+
executables: []
|
93
|
+
extensions:
|
94
|
+
- ext/eigen/extconf.rb
|
95
|
+
extra_rdoc_files: []
|
96
|
+
files:
|
97
|
+
- ".gitignore"
|
98
|
+
- ".travis.yml"
|
99
|
+
- ".yardopts"
|
100
|
+
- Gemfile
|
101
|
+
- LICENSE.txt
|
102
|
+
- README.md
|
103
|
+
- Rakefile
|
104
|
+
- bin/console
|
105
|
+
- bin/setup
|
106
|
+
- eigen.gemspec
|
107
|
+
- ext/eigen/eigen.cpp
|
108
|
+
- ext/eigen/extconf.rb
|
109
|
+
- lib/eigen.rb
|
110
|
+
- lib/eigen/affine3.rb
|
111
|
+
- lib/eigen/angle_axis.rb
|
112
|
+
- lib/eigen/isometry3.rb
|
113
|
+
- lib/eigen/matrix4.rb
|
114
|
+
- lib/eigen/matrixx.rb
|
115
|
+
- lib/eigen/quaternion.rb
|
116
|
+
- lib/eigen/vector3.rb
|
117
|
+
- lib/eigen/vectorx.rb
|
118
|
+
- lib/eigen/version.rb
|
119
|
+
homepage: https://github.com/rock-core/base-ruby_eigen
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.5.1
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Ruby bindings to the Eigen C++ linear algebra library
|
143
|
+
test_files: []
|
144
|
+
has_rdoc:
|