Class: Mageo::Octahedron
- Inherits:
-
Polyhedron
- Object
- Polyhedron
- Mageo::Octahedron
- Defined in:
- lib/mageo/octahedron.rb
Overview
3次元空間中の八面体を表現するクラス
Defined Under Namespace
Classes: InitializeError
Instance Attribute Summary
Attributes inherited from Polyhedron
Instance Method Summary collapse
-
#initialize(pairs) ⇒ Octahedron
constructor
八面体は 6個の頂点で構成されるが、これを3組の対体角で指定する。 e.g., [ [ [ -1, 0, 0 ], [ 1, 0, 0 ] ], [ [ 0, -1, 0 ], [ 0, 1, 0 ] ], [ [ 0, 0, -1 ], [ 0, 0, 1 ] ], ].
Methods inherited from Polyhedron
#center, #edges, #include?, #inside?, #shared_vertices, #translate, #translate!, #triangles, #volume
Constructor Details
#initialize(pairs) ⇒ Octahedron
八面体は 6個の頂点で構成されるが、これを3組の対体角で指定する。 e.g.,
[
[ [ -1, 0, 0 ], [ 1, 0, 0 ] ],
[ [ 0, -1, 0 ], [ 0, 1, 0 ] ],
[ [ 0, 0, -1 ], [ 0, 0, 1 ] ],
]
凸包であることのチェックは難しいのでしない。 TODO: 頂点が重複している、面上にあるなどのチェックも本来はすべきだが、入れていない。
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mageo/octahedron.rb', line 19 def initialize( pairs ) raise InitializeError if pairs.class != Array raise InitializeError if pairs.size != 3 pairs.each do |pair| raise InitializeError unless pair.class == Array raise InitializeError if pair.size != 2 pair.each do |pos| raise InitializeError if pos.size != 3 raise InitializeError unless pos.methods.include?( :[] ) raise InitializeError unless pos.methods.include?( :map ) end end pairs.flatten.each do |vertex| raise InitializeError if vertex.class == Mageo::Vector3DInternal end @vertices = [] pairs.each do |pair| pair.each do |vertex| @vertices << vertex.to_v3d end end @vertex_indices_of_triangles = [ [ 0, 2, 4], [ 0, 2, 5], [ 0, 3, 4], [ 0, 3, 5], [ 1, 2, 4], [ 1, 2, 5], [ 1, 3, 4], [ 1, 3, 5] ] end |