Sha256: 1a7b538c9af5145b1269a9094b6dc65362da2a4d5e52bfa256ee98567ebee864

Contents?: true

Size: 986 Bytes

Versions: 4

Compression:

Stored size: 986 Bytes

Contents

#! /usr/bin/env ruby
# coding: utf-8

#
# 直交座標系 3次元空間内の四面体を表現するクラス。
#
class Mageo::Tetrahedron < Mageo::Polyhedron

  class InitializeError < Exception; end

  # vertices には四面体の頂点を順不同で入れた Array。
  def initialize( vertices )
    raise InitializeError if vertices.class != Array
    raise InitializeError if vertices.size != 4
    vertices.each do |vertex|
      raise InitializeError if vertex.size != 3
      raise InitializeError unless vertex.methods.include?( :[] )
      raise InitializeError unless vertex.methods.include?( :map )
    end
    vertices.each do |vertex|
      raise InitializeError if vertex.class == Mageo::Vector3DInternal
    end

    @vertices = vertices.map { |vertex| vertex.to_v3d }

    @vertex_indices_of_triangles = [
      [ 0, 1, 2 ], 
      [ 1, 2, 3 ],
      [ 2, 3, 0 ], 
      [ 3, 0, 1 ],
    ]

    raise InitializeError, "volume is zero." if volume == 0.0
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mageo-0.0.5 lib/mageo/tetrahedron.rb
mageo-0.0.4 lib/mageo/tetrahedron.rb
mageo-0.0.3 lib/mageo/tetrahedron.rb
mageo-0.0.2 lib/mageo/tetrahedron.rb