tomato 1.2.4 Reference Manual

tomato - math::geometry 3D libraryTop, Main, Index

tomato math::geometry is an opensource geometry 3D library with basics functions for working in 3D space...
This Tcl package is inspired , copied (as best I could) from this great library written in .Net Math.NET Spatial. Some features for this class Quaternion are inspired by this python library pyquaternion.

Currently geometries supported are :

Vector A Class representing a Vector in 3D space
Ray A Class representing a Ray in 3D space
Point A Class representing a Point in 3D space
Plane A Class representing a Plane in 3D space
Matrix3d Helper class for working with 3D matrixes
Basic Matrix Defines the base class for Matrix classes (basic matrixes for CoordinateSystem, Matrix3d and Vector)
Line A Class representing a Line in 3D space
Coordinate System A Class representing a Coordinate System
Quaternion A Class representing a Quaternion
Triangle A Class representing a Triangle in 3D space

ExamplesTop, Main, Index

package require tomato
namespace path tomato
set v1 [mathvec3d::Vector3d new {1 0 0}]
set v2 [mathvec3d::Vector3d new 0 1 0]

set angletov1v2 [$v1 AngleTo $v2]
puts [helper::RadiansToDegrees $angletov1v2]
# 90.0
set v1 [mathvec3d::Vector3d new {1 0 0}]
set v2 [mathvec3d::Vector3d new {1 0 0}]
puts [$v1 IsParallelTo $v2]
# True
set p1  [mathpt3d::Point3d new {0 0 0}]
set p2  [mathpt3d::Point3d new {0 0 1}]

puts [$p1 DistanceTo $p2]
# 1
set p [mathpt3d::Point3d new {1 2 3}]
set angle 90
set css [mathcsys::RotationAngleVector $angle [mathvec3d::Vector3d new {0 0 1}]]
set rotatedPoint [$css Transform $p]
puts [$rotatedPoint ToString]
# -2 1 3
set plane [mathplane::Plane new [mathpt3d::Point3d new {0 0 0}] [mathvec3d::Vector3d new {0 0 1}]]
set projectedPoint [$plane Project [mathpt3d::Point3d new {1 2 3}]]
puts [$projectedPoint ToString]
# 1 2 0
set origin [mathpt3d::Point3d new {1 2 3}]
set xAxis  [mathvec3d::Vector3d new {1 0 0}]
set yAxis  [mathvec3d::Vector3d new {0 1 0}]
set zAxis  [mathvec3d::Vector3d new {0 0 1}]

set css [mathcsys::Csys new $origin $xAxis $yAxis $zAxis]

# Get baseclass
set base [$css BaseClass]
puts [$base ToMatrixString]
# Column1 = XAxis; Column2 = YAxis; Column3 = ZAxis; Column4 = Origin
# 
# 1 0 0 1
# 0 1 0 2
# 0 0 1 3
# 0 0 0 1
set ray [mathray3d::Ray3d new [mathpt3d::Point3d new {0 0 0}] [mathvec3d::Vector3d new {0 0 1}]]
set point3D [mathpt3d::Point3d new {1 0 0}]
set line3DTo [$ray ShortestLineTo $point3D]
puts [[$line3DTo StartPoint] ToString]
# 0 0 0
puts [[$line3DTo EndPoint] ToString]
# 1 0 0
set vector          [mathvec3d::Vector3d new 0 1 0]
set null_quaternion [mathquat::Quaternion new -axis $vector -angle 0]
set my_quaternion   [mathquat::Quaternion new -axis $vector -angle 90]

set mypoint [mathpt3d::Point3d new 0 0 4]

foreach q [tomato::mathquat::_intermediates $null_quaternion $my_quaternion 9 True] {
    set my_interpolated_point [$q Rotate $mypoint]
    puts "[$my_interpolated_point ToString] > Angle = [helper::RadiansToDegrees [$q Angle]] about Axis vector : \[[$vector ToString]\]"
}
# 0.0, 0.0, 4.0                               > Angle = 0.0  about Axis vector : [0, 1, 0]
# 0.6257378601609235, 0.0, 3.950753362380551  > Angle = 9.0  about Axis vector : [0, 1, 0]
# 1.2360679774997898, 0.0, 3.8042260651806146 > Angle = 18.0 about Axis vector : [0, 1, 0]
# 1.8159619989581872, 0.0, 3.564026096753471  > Angle = 27.0 about Axis vector : [0, 1, 0]
# 2.351141009169892, 0.0, 3.2360679774997894  > Angle = 36.0 about Axis vector : [0, 1, 0]
# 2.8284271247461903, 0.0, 2.82842712474619   > Angle = 45.0 about Axis vector : [0, 1, 0]
# 3.2360679774997894, 0.0, 2.351141009169892  > Angle = 54.0 about Axis vector : [0, 1, 0]
# 3.564026096753471, 0.0, 1.8159619989581879  > Angle = 63.0 about Axis vector : [0, 1, 0]
# 3.8042260651806146, 0.0, 1.2360679774997898 > Angle = 72.0 about Axis vector : [0, 1, 0]
# 3.9507533623805515, 0.0, 0.625737860160924  > Angle = 81.0 about Axis vector : [0, 1, 0]
# 4.0, 0.0, 8.881784197001252e-16             > Angle = 90.0 about Axis vector : [0, 1, 0]

LicenseTop, Main, Index


tomato math::geometry is covered under the terms of the MIT license.