Sha256: e7e58d375cc55f07c9149bd864b8e93dcc2ae1cc29ee08b1f6f000aba8bb5422

Contents?: true

Size: 1006 Bytes

Versions: 1

Compression:

Stored size: 1006 Bytes

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.0 lib/mageo/tetrahedron.rb