::tomato::mathtriangleTop, Main, Index
A Class representing a Triangle in 3D space
ClassesTop, Main, Index
Triangle [::tomato::mathtriangle]Top, Main, Index
Method summary
| Constructor for the class. | |
| Gets value that indicates whether any pair of elements in two specified points is not equal. | |
| Gets value that indicates whether each pair of elements in two specified points is equal. | |
| Returns the first point of the Triangle mathpt3d::Point3d. | |
| Gets Length of AB side. | |
| Gets Length of AC side. | |
| Gets Aera of the triangle. | |
| Gets Angle at the vertex A | |
| Gets Angle at the vertex B | |
| Gets Angle at the vertex C | |
| Returns the second point of the Triangle mathpt3d::Point3d. | |
| Gets Length of BC side. | |
| Angle bisector at the vertex A | |
| Angle bisector at the vertex B | |
| Angle bisector at the vertex C | |
| Returns the third point of the Triangle mathpt3d::Point3d. | |
| Gets Centroid of the triangle | |
| Gets the name of class. | |
| Finds the intersection... Möller–Trumbore_intersection_algorithm | |
| Gets Normal of the triangle mathvec3d::Vector3d. | |
| Gets Perimeter of the triangle. | |
| Convert triangle to plane object mathplane::Plane. |
constructor [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Initializes a new Triangle Class.
Triangle new ?args?
Parameters
args | Options described below. |
3 values | mathpt3d::Point3d |
list | 3 distinct values that represent the coordinates X, Y, Z. |
method constructor {args} { # Initializes a new Triangle Class. # # args - Options described below. # # 3 values - [mathpt3d::Point3d] # list - 3 distinct values that represent the coordinates X, Y, Z. # if {[llength $args] != 3} { error "Must be a list of 3 values... : \$args = [llength $args]" } set _triangle {} foreach val $args { if {[tomato::helper::TypeOf $val Isa "Point3d"]} { lappend _triangle $val } elseif {[string is list $val] && ([llength $val] == 3)} { lappend _triangle [tomato::mathpt3d::Point3d new {*}$val] } else { error "list of 3 values or 'Point3d' class..." } } if {[llength $_triangle] != 3} { error "Triangle must be a list of 3 values... : $_triangle" } if {[tomato::mathpt3d::IsCollinearPoints {*}$_triangle]} { error "Collinear points..." } lassign $_triangle _a _b _c }
!= [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets value that indicates whether any pair of elements in two specified points is not equal.
Parameters
other | The second triangle Triangle to compare. |
tolerance | A tolerance (epsilon) to adjust for floating point error. Optional, default $::tomato::helper::TolEquals. |
Return value
Returns True if the triangles are different. Otherwise False.
method != {other {tolerance {$::tomato::helper::TolEquals}}} { # Gets value that indicates whether any pair of elements in two specified points is not equal. # # other - The second triangle [Triangle] to compare. # tolerance - A tolerance (epsilon) to adjust for floating point error. # # Returns `True` if the triangles are different. Otherwise `False`. if {[llength [info level 0]] < 4} { set tolerance $::tomato::helper::TolEquals } return [expr {![tomato::mathtriangle::Equals [self] $other $tolerance]}] }
== [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets value that indicates whether each pair of elements in two specified points is equal.
Parameters
other | The second triangle Triangle to compare. |
tolerance | A tolerance (epsilon) to adjust for floating point error. Optional, default $::tomato::helper::TolEquals. |
Return value
Returns True if the triangles are the same. Otherwise False.
method == {other {tolerance {$::tomato::helper::TolEquals}}} { # Gets value that indicates whether each pair of elements in two specified points is equal. # # other - The second triangle [Triangle] to compare. # tolerance - A tolerance (epsilon) to adjust for floating point error. # # Returns `True` if the triangles are the same. Otherwise `False`. if {[llength [info level 0]] < 4} { set tolerance $::tomato::helper::TolEquals } return [expr {[tomato::mathtriangle::Equals [self] $other $tolerance]}] }
A [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Returns the first point of the Triangle mathpt3d::Point3d.
Return value
Returns the first point of the Triangle mathpt3d::Point3d.
method A {} { # Returns the first point of the Triangle [mathpt3d::Point3d]. return $_a }
AB [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets Length of AB side.
method AB {} { # Gets Length of AB side. return [$_a DistanceTo $_b] }
AC [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets Length of AC side.
method AC {} { # Gets Length of AC side. return [$_a DistanceTo $_c] }
Aera [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets Aera of the triangle.
method Aera {} { # Gets Aera of the triangle. set v1 [$_a VectorTo $_b] set v2 [$_a VectorTo $_c] return [expr {0.5 * [[$v1 CrossProduct $v2] Length]}] }
AngleA [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets Angle at the vertex A
Return value
Returns The angle in radian between the vectors, with a range between 0° and 180°
method AngleA {} { # Gets Angle at the vertex A # # Returns The angle in radian between the vectors, with a range between 0° and 180° set v1 [$_a VectorTo $_b] set v2 [$_a VectorTo $_c] return [$v1 AngleTo $v2] }
AngleB [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets Angle at the vertex B
Return value
Returns The angle in radian between the vectors, with a range between 0° and 180°
method AngleB {} { # Gets Angle at the vertex B # # Returns The angle in radian between the vectors, with a range between 0° and 180° set v1 [$_b VectorTo $_a] set v2 [$_b VectorTo $_c] return [$v1 AngleTo $v2] }
AngleC [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets Angle at the vertex C
Return value
Returns The angle in radian between the vectors, with a range between 0° and 180°
method AngleC {} { # Gets Angle at the vertex C # # Returns The angle in radian between the vectors, with a range between 0° and 180° set v1 [$_c VectorTo $_a] set v2 [$_c VectorTo $_b] return [$v1 AngleTo $v2] }
B [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Returns the second point of the Triangle mathpt3d::Point3d.
Return value
Returns the second point of the Triangle mathpt3d::Point3d.
method B {} { # Returns the second point of the Triangle [mathpt3d::Point3d]. return $_b }
BC [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets Length of BC side.
method BC {} { # Gets Length of BC side. return [$_b DistanceTo $_c] }
BisectorA [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Angle bisector at the vertex A
Return value
Returns mathline3d::Line3d
method BisectorA {} { # Angle bisector at the vertex A # # Returns [mathline3d::Line3d] set p [$_b + [[$_c - $_b] / [expr {1.0 + [my AC] / [my AB]}]]] return [tomato::mathline3d::Line3d new $_a $p] }
BisectorB [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Angle bisector at the vertex B
Return value
Returns mathline3d::Line3d
method BisectorB {} { # Angle bisector at the vertex B # # Returns [mathline3d::Line3d] set p [$_c + [[$_a - $_c] / [expr {1.0 + [my AB] / [my BC]}]]] return [tomato::mathline3d::Line3d new $_b $p] }
BisectorC [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Angle bisector at the vertex C
Return value
Returns mathline3d::Line3d
method BisectorC {} { # Angle bisector at the vertex C # # Returns [mathline3d::Line3d] set p [$_a + [[$_b - $_a] / [expr {1.0 + [my BC] / [my AC]}]]] return [tomato::mathline3d::Line3d new $_c $p] }
C [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Returns the third point of the Triangle mathpt3d::Point3d.
Return value
Returns the third point of the Triangle mathpt3d::Point3d.
method C {} { # Returns the third point of the Triangle [mathpt3d::Point3d]. return $_c }
Centroid [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets Centroid of the triangle
Return value
Returns mathpt3d::Point3d
method Centroid {} { # Gets Centroid of the triangle # # Returns [mathpt3d::Point3d] return [tomato::mathpt3d::Centroid [list $_a $_b $_c]] }
GetType [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets the name of class.
method GetType {} { # Gets the name of class. return [tomato::helper::TypeClass [self]] }
IntersectionWith [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Finds the intersection... Möller–Trumbore_intersection_algorithm
Parameters
obj | Options described below. |
tolerance | A tolerance (epsilon) to account for floating point error Optional, default $::tomato::helper::TolGeom. |
Line | mathline3d::Line3d |
Ray | mathray3d::Ray3d |
Description
An error exception is raised if $obj is not as described above.
Return value
Returns nothing is no intersection, A mathpt3d::Point3d if intersection.
method IntersectionWith {obj {tolerance {$::tomato::helper::TolGeom}}} { # Finds the intersection... # [Möller–Trumbore_intersection_algorithm](https://en.wikipedia.org/wiki/Möller–Trumbore_intersection_algorithm) # # obj - Options described below. # # Ray - [mathray3d::Ray3d] # Line - [mathline3d::Line3d] # tolerance - A tolerance (epsilon) to account for floating point error # # Returns nothing is no intersection, A [mathpt3d::Point3d] if intersection. if {[llength [info level 0]] < 4} { set tolerance $::tomato::helper::TolGeom } switch -glob [$obj GetType] { *Ray3d { set ip [tomato::mathplane::IntersectionWithRay [my ToPlane] $obj $tolerance] } *Line3d { set ip [tomato::mathplane::IntersectionWithLine [my ToPlane] $obj $tolerance] } default { #ruff # An error exception is raised if $obj is not as described above. error "Obj must be Line3d or Ray3d..." } } # get intersect point of line with triangle plane if {$ip eq ""} { # no intersection... return {} } set u [$_b VectorTo $_a] set v [$_c VectorTo $_a] set w [$ip VectorTo $_a] set uu [$u DotProduct $u] set uv [$u DotProduct $v] set vv [$v DotProduct $v] set wu [$w DotProduct $u] set wv [$w DotProduct $v] set D [expr {($uv * $uv) - ($uu * $vv)}] # ip is outside T ? set s [expr {(($uv * $wv) - ($vv * $wu)) / $D}] if {$s < 0.0 || $s > 1.0} { return "" } # ip is outside T ? set t [expr {(($uv * $wu) - ($uu * $wv)) / $D}] if {$t < 0.0 || ($s + $t) > 1.0} { return "" } return $ip }
Normal [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets Normal of the triangle mathvec3d::Vector3d.
method Normal {} { # Gets Normal of the triangle [mathvec3d::Vector3d]. set v1 [$_a VectorTo $_b] set v2 [$_a VectorTo $_c] return [$v1 CrossProduct $v2] }
Perimeter [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Gets Perimeter of the triangle.
method Perimeter {} { # Gets Perimeter of the triangle. return [expr {[my AB] + [my BC] + [my AC]}] }
ToPlane [::tomato::mathtriangle::Triangle]Triangle, Top, Main, Index
Convert triangle to plane object mathplane::Plane.
method ToPlane {} { # Convert triangle to plane object [mathplane::Plane]. return [tomato::mathplane::Plane new $_a [my Normal]] }
CommandsTop, Main, Index
Equals [::tomato::mathtriangle]Top, Main, Index
Gets a value to indicate if a pair of triangles are equal
Parameters
triangle | First input triangle Triangle |
other | Second input triangle Triangle |
tolerance | A 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 triangles are equal, otherwise false.
proc ::tomato::mathtriangle::Equals {triangle other tolerance} {
# Gets a value to indicate if a pair of triangles are equal
#
# triangle - First input triangle [Triangle]
# other - Second input triangle [Triangle]
# tolerance - A tolerance (epsilon) to adjust for floating point error
#
# Returns `True` if the triangles are equal, otherwise false.
#
# See : methods == !=
if {$tolerance < 0} {
#ruff
# An error exception is raised if tolerance (epsilon) < 0.
error "epsilon < 0"
}
return [expr {[[$triangle Centroid] == [$other Centroid] $tolerance] &&
(([$triangle Aera] - [$other Aera]) < $tolerance)
}]
}