tomato 1.2.4 Reference Manual

::tomato::mathcsysTop, Main, Index

A Class representing a Coordinate System.

ClassesTop, Main, Index

Csys [::tomato::mathcsys]Top, Main, Index

Method summary
constructorConstructor for the class.
!=Gets value that indicates whether any pair of elements in two specified coordinate system is not equal.
==Gets value that indicates whether each pair of elements in two specified coordinate system is equal.
BaseChangeMatrixGets the base change matrix
BaseClassGets the base class (Matrix obj)
GetTypeGets the name of class.
InvertInverts this coordinate system
OffsetByTranslates a coordinate system
OffsetToBaseGets the offset to origin
OriginGets the Origin
ResetRotationsResets rotations preserves scales
RotateCoordSysAroundVectorRotates a coordinate system around a vector
RotateNoResetRotate without Reset
SetTranslationGets a translation coordinate system
ToStringReturns a string representation of this object.
TransformTransforms...
TransformByTransforms...
TransformFromCoordSysTransforms obj according to the inverse of this change matrix
TransformToCoordSysTransforms obj according to this change matrix
TranslateCsysTranslates a coordinate system follow vector and distance
XAxisGets the X Axis
YAxisGets the Y Axis
ZAxisGets the Z Axis

constructor [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Initializes a new Coordinate System Class.

Csys create OBJNAME ?args?
Csys new ?args?
Parameters
argsOptions described below.
4 values4 distinct values :
The first value represents the origin mathpt3d::Point3d
The second value represents the Xaxis mathvec3d::Vector3d
The third value represents the Yaxis mathvec3d::Vector3d
The fourth value represents the Zaxis mathvec3d::Vector3d
MatrixA Matrix. mathmatrix::Matrix
Xaxis == Column 0
Yaxis == Column 1
Zaxis == Column 2
Origin == Column 3
no valuesdefault
Origin(0.0, 0.0, 0.0)
Xaxis(1.0, 0.0, 0.0)
Yaxis(0.0, 1.0, 0.0)
Zaxis(0.0, 0.0, 1.0)
Description

An error exception is raised if args is not the one desired.

method constructor {args} {

    # Initializes a new Coordinate System Class.
    #
    # args - Options described below.
    #
    # Matrix     - A Matrix. [mathmatrix::Matrix]<br>
    #              Xaxis  == Column 0<br>
    #              Yaxis  == Column 1<br>
    #              Zaxis  == Column 2<br>
    #              Origin == Column 3
    # 4 values   - 4 distinct values :<br>
    #              The first value represents the origin [mathpt3d::Point3d]<br>
    #              The second value represents the Xaxis [mathvec3d::Vector3d]<br>
    #              The third value represents the Yaxis [mathvec3d::Vector3d]<br>
    #              The fourth value represents the Zaxis [mathvec3d::Vector3d]<br>
    # no values  - default<br>
    #              `Origin(0.0, 0.0, 0.0)`<br>
    #              `Xaxis(1.0, 0.0, 0.0)`<br>
    #              `Yaxis(0.0, 1.0, 0.0)`<br>
    #              `Zaxis(0.0, 0.0, 1.0)`<br>

    if {[llength $args] == 1} {

        if {[tomato::helper::TypeOf $args Isa "Matrix"]} {

            set _baseclass $args
            set _xaxis   [tomato::mathvec3d::Vector3d new [lrange [$_baseclass GetColumn 0] 0 2]]
            set _yaxis   [tomato::mathvec3d::Vector3d new [lrange [$_baseclass GetColumn 1] 0 2]]
            set _zaxis   [tomato::mathvec3d::Vector3d new [lrange [$_baseclass GetColumn 2] 0 2]]
            set _origin  [tomato::mathpt3d::Point3d   new [lrange [$_baseclass GetColumn 3] 0 2]]
        } else {
            error "Must be a matrix if args equal to 1..."
        }

    } elseif {[llength $args] == 4} {

        foreach obj $args {
            if {![tomato::helper::IsaObject $obj]} {
                error "\$obj must be a object..."
            }
        }

        lassign $args _or v1 v2 v3

        if {![tomato::helper::TypeOf $_or Isa "Point3d"]} {
            error "\[lindex $args 0\] must be a Point3d..."
        }

        foreach obj [list $v1 $v2 $v3] {
            if {![tomato::helper::TypeOf $obj Isa "Vector3d"]} {
                error "\$obj must be a Vector3d..."
            }
        }

        set mat [tomato::mathmatrix::Matrix new 4 4]
        set _baseclass $mat

        set _xaxis   $v1
        set _yaxis   $v2
        set _zaxis   $v3
        set _origin $_or

        $mat SetColumn 0 [list {*}[$_xaxis Get] 0]
        $mat SetColumn 1 [list {*}[$_yaxis Get] 0]
        $mat SetColumn 2 [list {*}[$_zaxis Get] 0]
        $mat SetColumn 3 [list {*}[$_origin Get] 1]

    } elseif {[llength $args] == 0} {
        # default values
        set mat [tomato::mathmatrix::Matrix new 4 4]
        set _baseclass $mat

        set _xaxis  [tomato::mathvec3d::UnitX]
        set _yaxis  [tomato::mathvec3d::UnitY]
        set _zaxis  [tomato::mathvec3d::UnitZ]
        set _origin [tomato::mathpt3d::Point3d new 0 0 0]

        $mat SetColumn 0 [list {*}[$_xaxis Get] 0]
        $mat SetColumn 1 [list {*}[$_yaxis Get] 0]
        $mat SetColumn 2 [list {*}[$_zaxis Get] 0]
        $mat SetColumn 3 [list {*}[$_origin Get] 1]
    } else {
        #ruff
        # An error exception is raised if `args` is not the one desired.
        error "The argument does not match the requested values, please refer to the documentation..."
    }
}

!= [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Gets value that indicates whether any pair of elements in two specified coordinate system is not equal.

CSYSOBJ != other ?tolerance?
Parameters
otherThe second coordinate system Csys to compare.
toleranceA tolerance (epsilon) to adjust for floating point error. Optional, default $::tomato::helper::TolEquals.
Return value

Returns True if the coordinate system are different. Otherwise False.

method != {other {tolerance {$::tomato::helper::TolEquals}}} {

    # Gets value that indicates whether any pair of elements in two specified coordinate system is not equal.
    #
    # other - The second coordinate system [Csys] to compare.
    # tolerance - A tolerance (epsilon) to adjust for floating point error.
    #
    # Returns `True` if the coordinate system are different. Otherwise `False`.
    if {[llength [info level 0]] < 4} {
        set tolerance $::tomato::helper::TolEquals
    }

    return [expr {![tomato::mathcsys::Equals [self] $other $tolerance]}]
}

== [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Gets value that indicates whether each pair of elements in two specified coordinate system is equal.

CSYSOBJ == other ?tolerance?
Parameters
otherThe second coordinate system Csys to compare.
toleranceA tolerance (epsilon) to adjust for floating point error. Optional, default $::tomato::helper::TolEquals.
Return value

Returns True if the coordinate system are the same. Otherwise False.

method == {other {tolerance {$::tomato::helper::TolEquals}}} {

    # Gets value that indicates whether each pair of elements in two specified coordinate system is equal.
    #
    # other     - The second coordinate system [Csys] to compare.
    # tolerance - A tolerance (epsilon) to adjust for floating point error.
    #
    # Returns `True` if the coordinate system are the same. Otherwise `False`.
    if {[llength [info level 0]] < 4} {
        set tolerance $::tomato::helper::TolEquals
    }

    return [expr {[tomato::mathcsys::Equals [self] $other $tolerance]}]
}

BaseChangeMatrix [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Gets the base change matrix

CSYSOBJ BaseChangeMatrix
Return value

Returns A matrix mathmatrix::Matrix

method BaseChangeMatrix {} {

    # Gets the base change matrix
    #
    # Returns A matrix [mathmatrix::Matrix]
    set matrix [tomato::mathcsys::GetRotationSubMatrix [self]]
    set cs [tomato::mathcsys::SetRotationSubMatrix [$matrix Transpose] [self]]
    return [$cs BaseClass]
}

BaseClass [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Gets the base class (Matrix obj)

CSYSOBJ BaseClass
method BaseClass {} {

    # Gets the base class (Matrix obj)
    return $_baseclass
}

GetType [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Gets the name of class.

CSYSOBJ GetType
method GetType {} {

    # Gets the name of class.
    return [tomato::helper::TypeClass [self]]
}

Invert [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Inverts this coordinate system

CSYSOBJ Invert
Return value

Returns An inverted coordinate system Csys

method Invert {} {

    # Inverts this coordinate system
    #
    # Returns An inverted coordinate system [Csys]
    return [tomato::mathcsys::Csys new [[my BaseClass] Inverse]]
}

OffsetBy [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Translates a coordinate system

CSYSOBJ OffsetBy v
Parameters
va translation vector mathvec3d::Vector3d
Return value

Returns A new translated coordinate system Csys

method OffsetBy {v} {

    # Translates a coordinate system
    #
    # v - a translation vector [mathvec3d::Vector3d]
    #
    # Returns A new translated coordinate system [Csys]

    set vnormalize [$v Normalized]
    return [tomato::mathcsys::Csys new [[my Origin] + $vnormalize] [my XAxis] [my YAxis] [my ZAxis]]
}

OffsetToBase [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Gets the offset to origin

CSYSOBJ OffsetToBase
Return value

Returns A vector mathvec3d::Vector3d

method OffsetToBase {} {

    # Gets the offset to origin
    #
    # Returns A vector [mathvec3d::Vector3d]
    return [$_origin ToVector3D]
}

Origin [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Gets the Origin

CSYSOBJ Origin
Return value

Returns A point mathpt3d::Point3d

method Origin {} {

    # Gets the Origin
    #
    # Returns A point [mathpt3d::Point3d]
    return $_origin
}

ResetRotations [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Resets rotations preserves scales

CSYSOBJ ResetRotations
Return value

Returns A new coordinate system with reset rotation Csys

method ResetRotations {} {

    # Resets rotations preserves scales
    #
    # Returns A new coordinate system with reset rotation [Csys]

    set x [[[my XAxis] Length] * [tomato::mathvec3d::UnitX]]
    set y [[[my YAxis] Length] * [tomato::mathvec3d::UnitY]]
    set z [[[my ZAxis] Length] * [tomato::mathvec3d::UnitZ]]

    return [tomato::mathcsys::Csys new [my Origin] $x $y $z]
}

RotateCoordSysAroundVector [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Rotates a coordinate system around a vector

CSYSOBJ RotateCoordSysAroundVector about angle
Parameters
aboutA vector mathvec3d::Vector3d
angleAn angle in degrees
Return value

Returns A rotated coordinate system Csys

method RotateCoordSysAroundVector {about angle} {

    # Rotates a coordinate system around a vector
    #
    # about - A vector [mathvec3d::Vector3d]
    # angle - An angle in degrees
    #
    # Returns A rotated coordinate system [Csys]

    set rcs [tomato::mathcsys::RotationAngleVector $angle $about]
    return [$rcs Transform [self]]
}

RotateNoReset [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Rotate without Reset

CSYSOBJ RotateNoReset yaw pitch roll
Parameters
yawThe yaw
pitchThe pitch
rollThe roll
Return value

Returns A rotated coordinate system Csys

method RotateNoReset {yaw pitch roll} {

    # Rotate without Reset
    #
    # yaw - The yaw
    # pitch - The pitch
    # roll - The roll
    #
    # Returns A rotated coordinate system [Csys]

    set rcs [tomato::mathcsys::RotationByAngles $yaw $pitch $roll]
    return [$rcs Transform [self]]
}

SetTranslation [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Gets a translation coordinate system

CSYSOBJ SetTranslation v
Parameters
vmathvec3d::Vector3d
Return value

Returns A new coordinate system Csys

method SetTranslation {v} {

    # Gets a translation coordinate system
    #
    # v - [mathvec3d::Vector3d]
    #
    # Returns A new coordinate system [Csys]
    return [tomato::mathcsys::Csys new [$v ToPoint3D] [my XAxis] [my YAxis] [my ZAxis]]
}

ToString [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Returns a string representation of this object.

CSYSOBJ ToString
Return value

Returns a string representation of this object.

method ToString {} {

    # Returns a string representation of this object.
    lappend infocsys [list Origin: [$_origin ToString]]
    lappend infocsys [list XAxis: [$_xaxis ToString]]
    lappend infocsys [list YAxis: [$_yaxis ToString]]
    lappend infocsys [list ZAxis: [$_zaxis ToString]]

    return [join $infocsys ", "]
}

Transform [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Transforms...

CSYSOBJ Transform obj
Parameters
objOptions described below.
CsysCsys
Point3dmathpt3d::Point3d
Ray3dmathray3d::Ray3d
Vector3dmathvec3d::Vector3d
Return value

Returns a new obj transformed

method Transform {obj} {

    # Transforms...
    #
    # obj - Options described below.
    #
    # Csys     - [Csys]
    # Vector3d - [mathvec3d::Vector3d]
    # Point3d  - [mathpt3d::Point3d]
    # Ray3d    - [mathray3d::Ray3d]
    #
    # Returns a new obj transformed

    switch -glob [$obj GetType] {
        *Csys {
            return [tomato::mathcsys::Csys new [[my BaseClass] Multiply [$obj BaseClass]]]
        }
        *Vector3d {
            set matrix [tomato::mathcsys::GetRotationSubMatrix [self]]
            lassign [$matrix Multiply $obj] x y z

            return [tomato::mathvec3d::Vector3d new $x $y $z]
        }
        *Point3d {
            set mat [tomato::mathmatrix::Matrix new 1 4]
            $mat SetRow 0 [list {*}[$obj Get] 1]

            lassign [[my BaseClass] Multiply $mat] x y z

            return [tomato::mathpt3d::Point3d new $x $y $z]
        }
        *Ray3d {
            return [tomato::mathray3d::Ray3d new [my Transform [$obj ThroughPoint]] [my Transform [$obj Direction]]]
        }
        default {
            error "Entity must be Csys, Vector3d, Point3d or Ray3d..."
        }
    }
}

TransformBy [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Transforms...

CSYSOBJ TransformBy obj
Parameters
objOptions described below.
CsysCsys
Matrixmathmatrix::Matrix
Return value

Returns this by the coordinate system and returns the transformed if csys or a transformed coordinate system if matrix.

method TransformBy {obj} {

    # Transforms...
    #
    # obj - Options described below.
    #
    # Csys   - [Csys]
    # Matrix - [mathmatrix::Matrix]
    #
    # Returns this by the coordinate system and returns the transformed if csys or a transformed coordinate system if matrix.

    switch -glob [$obj GetType] {
        *Csys {
            return [$obj Transform [self]]
        }
        *Matrix {
            return [tomato::mathcsys::Csys new [$obj Multiply [my BaseClass]]]
        }
        default {
            error "Entity must be Csys or Matrix..."
        }
    }
}

TransformFromCoordSys [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Transforms obj according to the inverse of this change matrix

CSYSOBJ TransformFromCoordSys obj
Parameters
objOptions described below.
Point3dmathpt3d::Point3d
Ray3dmathray3d::Ray3d
Return value

Returns a transformed point mathpt3d::Point3d if Point3d or a transformed ray if Ray3d.

method TransformFromCoordSys {obj} {

    # Transforms obj according to the inverse of this change matrix
    #
    # obj - Options described below.
    #
    # Ray3d   - [mathray3d::Ray3d]
    # Point3d - [mathpt3d::Point3d]
    #
    # Returns a transformed point [mathpt3d::Point3d] if Point3d or a transformed ray if Ray3d.

    switch -glob [$obj GetType] {
        *Ray3d {
            set p  [$obj ThroughPoint]
            set uv [$obj Direction]

            set baseChangeMatrix [my BaseChangeMatrix]
            set matinv    [$baseChangeMatrix Inverse]
            set mattocsys [$matinv ToCsys]

            set point [[$mattocsys Transform $p] + [my OffsetToBase]]
            set direction [$mattocsys Transform $uv]

            return [tomato::mathray3d::Ray3d new $point $direction]
        }
        *Point3d {
            set baseChangeMatrix [my BaseChangeMatrix]
            return [[[[$baseChangeMatrix Inverse] ToCsys] Transform $obj] + [my OffsetToBase]]
        }
        default {
            error "Entity must be Ray3d Or Point3d..."
        }
    }
}

TransformToCoordSys [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Transforms obj according to this change matrix

CSYSOBJ TransformToCoordSys obj
Parameters
objOptions described below.
Point3dmathpt3d::Point3d
Ray3dmathray3d::Ray3d
Return value

Returns a transformed point if Point3d or a transformed ray mathray3d::Ray3d if Ray3d.

method TransformToCoordSys {obj} {

    # Transforms obj according to this change matrix
    #
    # obj - Options described below.
    #
    # Ray3d   - [mathray3d::Ray3d]
    # Point3d - [mathpt3d::Point3d]
    #
    # Returns a transformed point if Point3d or a transformed ray [mathray3d::Ray3d] if Ray3d.

    switch -glob [$obj GetType] {
        *Ray3d {
            set p  [$obj ThroughPoint]
            set uv [$obj Direction]

            set baseChangeMatrix [my BaseChangeMatrix]

            # The position and the vector are transformed
            set point [[[$baseChangeMatrix ToCsys] Transform $p] + [my OffsetToBase]]
            set direction [$uv TransformBy $baseChangeMatrix]

            return [tomato::mathray3d::Ray3d new $point $direction]
        }
        *Point3d {
            set baseChangeMatrix [my BaseChangeMatrix]
            return [[[$baseChangeMatrix ToCsys] Transform $obj] + [my OffsetToBase]]
        }
        default {
            error "Entity must be Ray3d Or Point3d..."
        }
    }
}

TranslateCsys [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Translates a coordinate system follow vector and distance

CSYSOBJ TranslateCsys v d
Parameters
va translation vector mathvec3d::Vector3d
dDistance translation
Return value

Returns A new translated coordinate system Csys

method TranslateCsys {v d} {

    # Translates a coordinate system follow vector and distance
    #
    # v - a translation vector [mathvec3d::Vector3d]
    # d - Distance translation
    #
    # Returns A new translated coordinate system [Csys]
    return [tomato::mathcsys::Csys new [[my Origin] TranslatePoint $v $d] [my XAxis] [my YAxis] [my ZAxis]]
}

XAxis [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Gets the X Axis

CSYSOBJ XAxis
Return value

Returns A vector mathvec3d::Vector3d

method XAxis {} {

    # Gets the X Axis
    #
    # Returns A vector [mathvec3d::Vector3d]
    return $_xaxis
}

YAxis [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Gets the Y Axis

CSYSOBJ YAxis
Return value

Returns A vector mathvec3d::Vector3d

method YAxis {} {

    # Gets the Y Axis
    #
    # Returns A vector [mathvec3d::Vector3d]
    return $_yaxis
}

ZAxis [::tomato::mathcsys::Csys]Csys, Top, Main, Index

Gets the Z Axis

CSYSOBJ ZAxis
Return value

Returns A vector mathvec3d::Vector3d

method ZAxis {} {

    # Gets the Z Axis
    #
    # Returns A vector [mathvec3d::Vector3d]
    return $_zaxis
}

CommandsTop, Main, Index

CreateMappingCoordinateSystem [::tomato::mathcsys]Top, Main, Index

Creates a coordinate system that maps from the from coordinate system to the to coordinate system.

CreateMappingCoordinateSystem fromCs toCs
Parameters
fromCsThe from coordinate system Csys
toCsThe to coordinate system Csys
Return value

Returns A mapping coordinate system Csys

proc ::tomato::mathcsys::CreateMappingCoordinateSystem {fromCs toCs} {

    # Creates a coordinate system that maps from the `from` coordinate system to the `to` coordinate system.
    #
    # fromCs - The from coordinate system [Csys]
    # toCs   - The to coordinate system [Csys]
    #
    # Returns A mapping coordinate system [Csys]
    set singular 0
    set det -1

    try {
        set det [[$fromCs BaseClass] Determinant]
    } trap {singular} {} {
        set singular 1
    } on error {msg} {
        error $msg
    }

    if {$singular || (abs($det) < $::tomato::helper::TolEquals)} {
        set mat [[$toCs BaseClass] Multiply [$fromCs BaseClass]]
    } else {
        set mat [[$toCs BaseClass] Multiply [[$fromCs BaseClass] Inverse]]
    }

    $mat SetCell 3 3 1.0

    return [tomato::mathcsys::Csys new $mat]
}

Equals [::tomato::mathcsys]Top, Main, Index

Indicate if this coordinate system is equivalent to a another coordinate system

Equals cs other tolerance
Parameters
csFirst input coordinate system Csys
otherSecond input coordinate system Csys
toleranceA tolerance (epsilon) to adjust for floating point error
Description

See : methods == !=

An error exception is raised if tolerance (epsilon) < 0.

Return value

Returns True if the coordinate system are equal, otherwise false.

proc ::tomato::mathcsys::Equals {cs other tolerance} {

    # Indicate if this coordinate system is equivalent to a another coordinate system
    #
    # cs - First input coordinate system  [Csys]
    # other - Second input coordinate system  [Csys]
    # tolerance - A tolerance (epsilon) to adjust for floating point error
    #
    # Returns `True` if the coordinate system are equal, otherwise false.
    #
    # See : methods == !=
    if {$tolerance < 0} {
        #ruff
        # An error exception is raised if tolerance (epsilon) < 0.
        error "epsilon < 0"
    }
    return [expr {
                  [tomato::mathpt3d::Equals  [$cs Origin] [$other Origin] $tolerance] &&
                  [tomato::mathvec3d::Equals [$cs XAxis] [$other XAxis] $tolerance] &&
                  [tomato::mathvec3d::Equals [$cs YAxis] [$other YAxis] $tolerance] &&
                  [tomato::mathvec3d::Equals [$cs ZAxis] [$other ZAxis] $tolerance]
                }]
}

GetRotationSubMatrix [::tomato::mathcsys]Top, Main, Index

Gets a rotation submatrix from a coordinate system

GetRotationSubMatrix coordinateSystem
Parameters
coordinateSystemCsys
Return value

Returns A rotation matrix mathmatrix::Matrix

proc ::tomato::mathcsys::GetRotationSubMatrix {coordinateSystem} {

    # Gets a rotation submatrix from a coordinate system
    #
    # coordinateSystem - [Csys]
    #
    # Returns A rotation matrix [mathmatrix::Matrix]
    set csbase [$coordinateSystem BaseClass]
    return [$csbase SubMatrix 0 3 0 3]
}

Parse [::tomato::mathcsys]Top, Main, Index

Transform a list to coordinate system

Parse ?args?
Parameters
argsOptions described below.
Description

The first value represents the origin [Tcl list]
The second value represents the Xaxis [Tcl list]
The third value represents the Yaxis [Tcl list]
The fourth value represents the Zaxis [Tcl list]

Return value

Returns A new coordinate system Csys

proc ::tomato::mathcsys::Parse {args} {

    # Transform a list to coordinate system
    #
    # args - Options described below.
    #
    # The first  value represents the origin \[Tcl list]<br>
    # The second value represents the Xaxis \[Tcl list]<br>
    # The third  value represents the Yaxis \[Tcl list]<br>
    # The fourth value represents the Zaxis \[Tcl list]<br>
    #
    # Returns A new coordinate system [Csys]

    if {[llength $args] == 1} {

        if {[llength {*}$args] != 4} {
            error "must be a list 4 elements..."
        }

        lassign {*}$args or vx vy vz

        set p  [tomato::mathpt3d::Point3d new $or]
        set v1 [tomato::mathvec3d::Vector3d new $vx]
        set v2 [tomato::mathvec3d::Vector3d new $vy]
        set v3 [tomato::mathvec3d::Vector3d new $vz]

        return [tomato::mathcsys::Csys new $p $v1 $v2 $v3]

    } elseif {[llength $args] == 4} {

        lassign $args or vx vy vz

        set p  [tomato::mathpt3d::Point3d new $or]
        set v1 [tomato::mathvec3d::Vector3d new $vx]
        set v2 [tomato::mathvec3d::Vector3d new $vy]
        set v3 [tomato::mathvec3d::Vector3d new $vz]

        return [tomato::mathcsys::Csys new $p $v1 $v2 $v3]

    } else {
        error "must be a list of 1 with 4 sub lists or 4 elements..."
    }
}

Pitch [::tomato::mathcsys]Top, Main, Index

Rotates around Y

Pitch av
Parameters
avAngle in degrees
Return value

Returns A rotated coordinate system Csys

proc ::tomato::mathcsys::Pitch {av} {

    # Rotates around Y
    #
    # av - Angle  in degrees
    #
    # Returns A rotated coordinate system [Csys]
    return [tomato::mathcsys::RotationAngleVector $av [tomato::mathvec3d::UnitY]]
}

Roll [::tomato::mathcsys]Top, Main, Index

Rotates around X

Roll av
Parameters
avAngle in degrees
Return value

Returns A rotated coordinate system Csys

proc ::tomato::mathcsys::Roll {av} {

    # Rotates around X
    #
    # av - Angle  in degrees
    #
    # Returns A rotated coordinate system [Csys]
    return [tomato::mathcsys::RotationAngleVector $av [tomato::mathvec3d::UnitX]]
}

RotateTo [::tomato::mathcsys]Top, Main, Index

Sets to the matrix of rotation that aligns the from vector with the to vector.
The optional Axis argument may be used when the two vectors are perpendicular and in opposite directions
to specify a specific solution, but is otherwise ignored.

RotateTo fromVector3D toVector3D ?axis?
Parameters
fromVector3DInput Vector object to align from.
toVector3DInput Vector object to align to.
axisInput Vector object. Optional, default null.
Return value

Returns A rotated coordinate system Csys

proc ::tomato::mathcsys::RotateTo {fromVector3D toVector3D {axis null}} {

    # Sets to the matrix of rotation that aligns the `from` vector with the `to` vector.<br>
    # The optional Axis argument may be used when the two vectors are perpendicular and in opposite directions<br>
    # to specify a specific solution, but is otherwise ignored.<br>
    #
    # fromVector3D - Input Vector object to align from.
    # toVector3D   - Input Vector object to align to.
    # axis         - Input Vector object.
    #
    # Returns A rotated coordinate system [Csys]

    set r [tomato::mathmatrix3d::RotationTo $fromVector3D $toVector3D $axis]
    set coordinateSystem [tomato::mathcsys::Csys new]

    return [tomato::mathcsys::SetRotationSubMatrix $r $coordinateSystem]
}

RotationAngleVector [::tomato::mathcsys]Top, Main, Index

Creates a rotating coordinate system

RotationAngleVector angle v
Parameters
angleAngle to rotate in degrees
vVector to rotate about mathvec3d::Vector3d
Return value

Returns A rotating coordinate system Csys

proc ::tomato::mathcsys::RotationAngleVector {angle v} {

    # Creates a rotating coordinate system
    #
    # angle - Angle to rotate in degrees
    # v   - Vector to rotate about [mathvec3d::Vector3d]
    #
    # Returns A rotating coordinate system [Csys]

    set mat [tomato::mathmatrix::Matrix new 4 4]
    $mat SetSubMatrix 0 3 0 3 [tomato::mathmatrix3d::RotationAroundArbitraryVector  [$v Normalized]  [tomato::helper::DegreesToRadians $angle]  ]

    $mat SetCell 3 3 1.0

    return [tomato::mathcsys::Csys new $mat]
}

RotationByAngles [::tomato::mathcsys]Top, Main, Index

Successive intrinsic rotations around Z (yaw) then around Y (pitch) and then around X (roll) Gives an order of magnitude speed improvement. https://en.wikipedia.org/wiki/Rotation_matrix#General_rotations

RotationByAngles yaw pitch roll
Parameters
yawRotates around Z (angle in degrees)
pitchRotates around Y (angle in degrees)
rollRotates around X (angle in degrees)
Return value

Returns A rotated coordinate system Csys

proc ::tomato::mathcsys::RotationByAngles {yaw pitch roll} {

    # Successive intrinsic rotations around Z (yaw) then around Y (pitch) and then around X (roll)
    # Gives an order of magnitude speed improvement.
    # https://en.wikipedia.org/wiki/Rotation_matrix#General_rotations
    #
    # yaw   - Rotates around Z (angle in degrees)
    # pitch - Rotates around Y (angle in degrees)
    # roll  - Rotates around X (angle in degrees)
    #
    # Returns A rotated coordinate system [Csys]

    set yR [tomato::helper::DegreesToRadians $yaw]
    set pR [tomato::helper::DegreesToRadians $pitch]
    set rR [tomato::helper::DegreesToRadians $roll]

    set cosY [expr {cos($yR)}]
    set sinY [expr {sin($yR)}]
    set cosP [expr {cos($pR)}]
    set sinP [expr {sin($pR)}]
    set cosR [expr {cos($rR)}]
    set sinR [expr {sin($rR)}]

    set origin [tomato::mathpt3d::Point3d new]

    set xAxis  [tomato::mathvec3d::Vector3d new  [expr {$cosY * $cosP}]  [expr {$sinY * $cosP}]  [expr {Inv($sinP)}]  ]

    set yAxis  [tomato::mathvec3d::Vector3d new  [expr {($cosY * $sinP * $sinR) - ($sinY * $cosR)}]  [expr {($sinY * $sinP * $sinR) + ($cosY * $cosR)}]  [expr {$cosP * $sinR}]  ]

    set zAxis  [tomato::mathvec3d::Vector3d new  [expr {($cosY * $sinP * $cosR) + ($sinY * $sinR)}]  [expr {($sinY * $sinP * $cosR) - ($cosY * $sinR)}]  [expr {$cosP * $cosR}]  ]

    return [tomato::mathcsys::Csys new $origin $xAxis $yAxis $zAxis]
}

SetRotationSubMatrix [::tomato::mathcsys]Top, Main, Index

Creates a rotating coordinate system

SetRotationSubMatrix r coordinateSystem
Parameters
rA 3x3 matrix with the rotation portion mathmatrix::Matrix
coordinateSystemA rotated coordinate system Csys
Return value

Returns A rotating coordinate system Csys

proc ::tomato::mathcsys::SetRotationSubMatrix {r coordinateSystem} {

    # Creates a rotating coordinate system
    #
    # r                  - A 3x3 matrix with the rotation portion [mathmatrix::Matrix]
    # coordinateSystem   - A rotated coordinate system [Csys]
    #
    # Returns A rotating coordinate system [Csys]
    if {[$r RowCount] != 3 || [$r ColumnCount] != 3} {
        error "[tomato::helper::TypeClass $r] must be Matrix3x3..."
    }

    set cs [tomato::mathcsys::Csys new [$coordinateSystem Origin]  [$coordinateSystem XAxis]  [$coordinateSystem YAxis]  [$coordinateSystem ZAxis]  ]

    set csbase [$cs BaseClass]
    $csbase SetSubMatrix 0 [$r RowCount] 0 [$r ColumnCount] $r

    return [tomato::mathcsys::Csys new $csbase]
}

SetToAlignCoordinateSystems [::tomato::mathcsys]Top, Main, Index

Sets this matrix to be the matrix that maps from the from coordinate system to the to coordinate system.

SetToAlignCoordinateSystems fromOrigin fromXAxis fromYAxis fromZAxis toOrigin toXAxis toYAxis toZAxis
Parameters
fromOriginInput mathpt3d::Point3d that defines the origin to map the coordinate system from
fromXAxisInput mathvec3d::Vector3d that defines the X-axis to map the coordinate system from.
fromYAxisInput mathvec3d::Vector3d that defines the Y-axis to map the coordinate system from.
fromZAxisInput mathvec3d::Vector3d that defines the Z-axis to map the coordinate system from.
toOriginInput mathpt3d::Point3d that defines the origin to map the coordinate system to.
toXAxisInput mathvec3d::Vector3d that defines the X-axis to map the coordinate system to.
toYAxisInput mathvec3d::Vector3d that defines the Y-axis to map the coordinate system to.
toZAxisInput mathvec3d::Vector3d that defines the Z-axis to map the coordinate system to.
Return value

Returns A mapping coordinate system Csys

proc ::tomato::mathcsys::SetToAlignCoordinateSystems {fromOrigin fromXAxis fromYAxis fromZAxis toOrigin toXAxis toYAxis toZAxis} {

    # Sets this matrix to be the matrix that maps from the `from` coordinate system to the `to` coordinate system.
    #
    # fromOrigin - Input [mathpt3d::Point3d]   that defines the origin to map the coordinate system from
    # fromXAxis  - Input [mathvec3d::Vector3d] that defines the X-axis to map the coordinate system from.
    # fromYAxis  - Input [mathvec3d::Vector3d] that defines the Y-axis to map the coordinate system from.
    # fromZAxis  - Input [mathvec3d::Vector3d] that defines the Z-axis to map the coordinate system from.
    # toOrigin   - Input [mathpt3d::Point3d]   that defines the origin to map the coordinate system to.
    # toXAxis    - Input [mathvec3d::Vector3d] that defines the X-axis to map the coordinate system to.
    # toYAxis    - Input [mathvec3d::Vector3d] that defines the Y-axis to map the coordinate system to.
    # toZAxis    - Input [mathvec3d::Vector3d] that defines the Z-axis to map the coordinate system to.
    #
    # Returns A mapping coordinate system [Csys]

    set cs1 [tomato::mathcsys::Csys new $fromOrigin $fromXAxis $fromYAxis $fromZAxis]
    set cs2 [tomato::mathcsys::Csys new $toOrigin $toXAxis $toYAxis $toZAxis]
    set mcs [tomato::mathcsys::CreateMappingCoordinateSystem $cs1 $cs2]

    return $mcs
}

Translation [::tomato::mathcsys]Top, Main, Index

Creates a translation.

Translation translation
Parameters
translationA translation vector mathvec3d::Vector3d
Return value

Returns A translated coordinate system Csys

proc ::tomato::mathcsys::Translation {translation} {

    # Creates a translation.
    #
    # translation - A translation vector [mathvec3d::Vector3d]
    #
    # Returns A translated coordinate system [Csys]
    return [tomato::mathcsys::Csys new [$translation ToPoint3D] [tomato::mathvec3d::UnitX] [tomato::mathvec3d::UnitY] [tomato::mathvec3d::UnitZ]]
}

Yaw [::tomato::mathcsys]Top, Main, Index

Rotates around Z

Yaw av
Parameters
avAngle in degrees
Return value

Returns A rotated coordinate system Csys

proc ::tomato::mathcsys::Yaw {av} {

    # Rotates around Z
    #
    # av - Angle  in degrees
    #
    # Returns A rotated coordinate system [Csys]
    return [tomato::mathcsys::RotationAngleVector $av [tomato::mathvec3d::UnitZ]]
}