Sha256: 2a0704ed2bdb6cd011234058111e88ea4779918ecb9a82704a6258d41e35a629

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

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

require "mageo/vector3d.rb"
require "mageo/triangle.rb"
require "mageo/polyhedron.rb"


#
# 直交座標系 3次元空間内の四面体を表現するクラス。
#
class Tetrahedron < 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 == 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

1 entries across 1 versions & 1 rubygems

Version Path
mageo-0.0.1 lib/mageo/tetrahedron.rb