Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akicho8/stylet_support
GUIに依存しない数学関連ライブラリ
https://github.com/akicho8/stylet_support
library mathematics vector
Last synced: 3 days ago
JSON representation
GUIに依存しない数学関連ライブラリ
- Host: GitHub
- URL: https://github.com/akicho8/stylet_support
- Owner: akicho8
- Created: 2013-11-02T10:19:16.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2022-04-20T11:03:30.000Z (over 2 years ago)
- Last Synced: 2024-10-11T17:26:46.681Z (about 1 month ago)
- Topics: library, mathematics, vector
- Language: Ruby
- Homepage:
- Size: 2.09 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
* GUIに依存しない数学関連ライブラリ
#+BEGIN_SRC ruby
Point.new # => [0.0, 0.0]
Point[1, 2] # => [1, 2]
Point[1, 2].members # => [:x, :y]
Point[1, 2].values # => [1, 2]
Point[1, 2] # => [1, 2]Vector.superclass # => Stylet::Point2
Point.new(Point[1,2]) # => [1, 2]
Point[Point[1,2]] # => [1, 2]Vector.new # => [0.0, 0.0]
Vector.new # => [0.0, 0.0]
Vector.new(1, 2) # => [1, 2]Vector.zero # => [0.0, 0.0]
Vector.one # => [1.0, 1.0]a = Vector[1, 2]
b = Vector[3, 4]a + b # => [4.0, 6.0]
a - b # => [-2.0, -2.0]
a * 2 # => [2.0, 4.0]
a / 2 # => [0.5, 1.0]a.add(b) # => [4.0, 6.0]
a.sub(b) # => [-2.0, -2.0]
a.scale(2) # => [2.0, 4.0]
a.mul(2) # => [2.0, 4.0]
a.div(2) # => [0.5, 1.0]a + [3, 4] # => [4.0, 6.0]
a - [3, 4] # => [-2.0, -2.0]Vector.one.reverse # => [-1.0, -1.0]
-Vector.one # => [-1.0, -1.0]Vector[3, 4].normalize # => [0.6, 0.8]
Vector.one.normalize # => [0.7071067811865475, 0.7071067811865475]
Vector.one.magnitude # => 1.4142135623730951
Vector.one.magnitude_sq # => 2.0v = Vector.rand
v.round(2) # => [-1.0, -0.88]
v.round # => [-1, -1]
v.floor # => [-1, -1]
v.ceil # => [0, 0]
v.truncate # => [0, 0]Vector.rand # => [-0.5758140223421724, -0.23276547457672714]
Vector.rand(3) # => [1, 1]
Vector.rand(3..4) # => [4, 4]
Vector.rand(3.0..4) # => [3.9402342251571714, 3.550203689124972]
Vector.rand(-2.0..2.0) # => [-1.181268220930995, 1.4942116900421252]Vector[1, 0].dot_product(Vector[1, 0]) # => 1
Vector[1, 0].dot_product(Vector[-1, 0]) # => -1Vector.cross_product(Vector.rand, Vector.rand) # => -0.7348374986070235
Vector.rand.distance_to(Vector.rand) # => 1.7226903872525836
v = Vector.new
v.object_id # => 70298637530620
v.replace(Vector.rand) # => [-0.2619785178209082, -0.4396795163426983]
v.object_id # => 70298637530620Vector.zero.distance_to(Vector.one) # => 1.4142135623730951
Vector.zero.zero? # => true
Vector.one.nonzero? # => trueVector.zero.inspect # => "[0.0, 0.0]"
Vector.zero.to_s # => "[0.0, 0.0]"Vector[1,2].prep # => [-2, 1]
#+END_SRC** TIPS
*** 当たり判定を高速化するには?
当たり判定を次のようにしているとき
#+BEGIN_SRC ruby
if v.magnitude < r
end
#+END_SRC次のようにすると sqrt を省略できる
#+BEGIN_SRC ruby
if v.magnitude_sq < r ** 2
end
#+END_SRC*** a地点からb地点へのベクトルを求めるには?
#+BEGIN_SRC ruby
b - a
#+END_SRC