quaternion 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c189f435b49a8ec52111f49762b9f3401acff57c
4
- data.tar.gz: 5114e0133f4e73eb7f50baa31036457863d40a26
3
+ metadata.gz: 819da0242c1ec7196ca1cf3ac0e5e11004235696
4
+ data.tar.gz: c8b70be61075d0ead7570014bcbc5f306d88e465
5
5
  SHA512:
6
- metadata.gz: d7a653a9ec36bea1e216b58de34396c5c8fefdda9d1e000b7e557cbbd667a67b5a80c82f16effcb28576253a61687907ac4c7b16f1755b47549e26fd4b91775b
7
- data.tar.gz: b496fde8478ffa2d2719fc63f1062016cb7efab8f4a50413f79f33a5f7d3210923b254067a721ed18c6bfb258d21b3ba72069cf347bb859ab3382f86fc8e5ff4
6
+ metadata.gz: 6f67f4c07fb013157cd9230ce6fbd35c1d5d084616449b4c8337e1989dcd32577404a1fc273fda2ec99877b800c62b7948f0d23c2a2fddb9de7832a4f232fd54
7
+ data.tar.gz: 4c7f6ca6b558480f4bde5be720c22c13ff2f9e2579a5364a167f77a9d8f7bf1f14726a69a35a9ea0d627cccbf6adb3f699758338676215154eeaae6e5371151d
@@ -1,3 +1,3 @@
1
1
  class Quaternion
2
- VERSION = "0.1.0" # :nodoc:
2
+ VERSION = "0.1.1" # :nodoc:
3
3
  end
data/lib/quaternion.rb CHANGED
@@ -9,6 +9,24 @@ require "#{root_dir}/lib/quaternion/numeric"
9
9
  class Quaternion
10
10
  include Math
11
11
 
12
+ ##
13
+ # Returns an instance of Quaternion for rotateion aroud +axis+ with angle
14
+ # +theta+.
15
+ # qrot = Quaternion.rotation([1.0, 1.0, 1.0], PI/2.0)
16
+ def self.rotation axis, theta
17
+ case axis
18
+ when Array
19
+ axis = Vector.elements(axis, true)
20
+ axis = axis.normalize
21
+ when Vector
22
+ axis = axis.normalize
23
+ else
24
+ raise ArgumentError, "Invalid type"
25
+ end
26
+
27
+ return Quaternion.new(cos(theta/2.0), axis*sin(theta/2.0))
28
+ end
29
+
12
30
  ##
13
31
  # Returns an instance of Quaternion.
14
32
  # The following code instanciate a quaternion of
@@ -221,5 +239,35 @@ class Quaternion
221
239
  return "Quaternion(#{@w}; #{@v})"
222
240
  end
223
241
  alias to_s inspect
242
+
243
+ ##
244
+ # Rotates a point +v+. This method does not check if the quaternion's norm is
245
+ # 1 or not.
246
+ # qrot = Quaternion.rotation([1.0, 1.0, 1.0], PI/2.0)
247
+ # qrot.rotate([1.0, 0.0, 0.0]) # =>[0.3333333333333334, 0.9106836025229592, -0.24401693585629253]
248
+ def rotate v
249
+ q_v = Quaternion.new(0.0, v)
250
+
251
+ res = self*q_v*(self.conjugate)
252
+
253
+ case v
254
+ when Array
255
+ return res[:v].to_a
256
+ when Vector
257
+ return res[:v]
258
+ end
259
+ end
260
+
261
+ private
262
+ def to_vector v
263
+ case v
264
+ when Array
265
+ Vector.elements(v, true)
266
+ when Vector
267
+ v.clone
268
+ else
269
+ raise ArgumentError, "Fail to convert to Vector"
270
+ end
271
+ end
224
272
  end
225
273
 
data/quaternion.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = %q{Quaternion class}
12
12
  #spec.description = %q{TODO: Write a longer description or delete this line.}
13
- #spec.homepage = "TODO: Put your gem's website or public repo URL here."
13
+ spec.homepage = "https://github.com/tanahiro/quaternion"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -18,10 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- #if spec.respond_to?(:metadata)
22
- # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
23
- #end
24
-
25
21
  spec.required_ruby_version = '>= 2.2.1'
26
22
 
27
23
  spec.add_development_dependency "bundler", "~> 1.9"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quaternion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki Tanaka
@@ -71,7 +71,7 @@ files:
71
71
  - lib/quaternion/numeric.rb
72
72
  - lib/quaternion/version.rb
73
73
  - quaternion.gemspec
74
- homepage:
74
+ homepage: https://github.com/tanahiro/quaternion
75
75
  licenses:
76
76
  - MIT
77
77
  metadata: {}