Contents
- Description
- Constructor Summary
- Method Summary
- Constructor Details
- Method Details
- copy(Triangle3D)
- set(double, double, double, double, double, double, double, double, double)
- set(Point3D, Point3D, Point3D)
- point(int)
- center()
- normal()
- plane()
- isInside(Point3D)
- distanceFromEdge(Point3D)
- intersection(Line3D, List)
- intersectionRay(Line3D, List)
- intersectionSegment(Line3D, List)
- translateXYZ(double, double, double)
- rotateX(double)
- rotateY(double)
- rotateZ(double)
- show()
- toString()
Class Triangle3D
java.lang.Object
org.jlab.geom.prim.Triangle3D
- All Implemented Interfaces:
Face3D
,Transformable
,Showable
A 3D triangle represented by three points.
Since any three points in 3D space that are not collinear define a plane,
a triangle can be converted into a plane via plane()
.
The normal of the surface of a triangle is oriented such that when looking antiparallel to the normal towards the triangle the triangle's points wound counterclockwise. Conversely, when looking in a direction parallel to the normal, the points are wound in a clockwise fashion.
The intersection of a line with a triangle can be calculated using the
intersection methods:
intersection(...)
,
intersectionRay(...)
,
intersectionSegment(...)
.
- Author:
- gavalian
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newTriangle3D
with all three points at the origin.Triangle3D
(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2) Constructs a newTriangle3D
with the points at the specified coordinates.Triangle3D
(Point3D point0, Point3D point1, Point3D point2) Constructs a newTriangle3D
from the given points.Triangle3D
(Triangle3D triangle) Constructs a newTriangle3D
with its points coinciding with the points of the given triangle. -
Method Summary
Modifier and TypeMethodDescriptioncenter()
Constructs a newPoint3D
at the geometric mean of the three points in thisTriangle3D
.void
copy
(Triangle3D triangle) Sets the points of thisTriangle3D
to coincide with points of the given triangle.double
Computes the minimum distance of the given point from the edges of thisTriangle3D
.int
intersection
(Line3D line, List<Point3D> intersections) Finds the intersections of the given infinite line with thisFace3D
.int
intersectionRay
(Line3D line, List<Point3D> intersections) Finds the intersections of the given ray with thisFace3D
.int
intersectionSegment
(Line3D line, List<Point3D> intersections) Finds the intersections of the given line segment with thisFace3D
.boolean
Test whether the given point is inside the area of thisTriangle3D
.normal()
Constructs the unit vector normal to the plane of thisTriangle3D
.plane()
Constructs the the plane of thisTriangle3D
.point
(int index) Returns the point from thisFace3D
with corresponding index.void
rotateX
(double angle) Rotates this object clockwise around the x axis.void
rotateY
(double angle) Rotates this object clockwise around the y axis.void
rotateZ
(double angle) Rotates this object clockwise around the z axis.void
set
(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2) Sets the points of the triangle to coincide with the given coordinates.void
Sets the points of thisTriangle3D
to coincide with the given points.void
show()
InvokesSystem.out.println(this)
.toString()
void
translateXYZ
(double x, double y, double z) Translates this object linearly by the amounts specified.
-
Constructor Details
-
Triangle3D
public Triangle3D()Constructs a newTriangle3D
with all three points at the origin. -
Triangle3D
public Triangle3D(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2) Constructs a newTriangle3D
with the points at the specified coordinates.- Parameters:
x0
- x coordinate of the first pointy0
- y coordinate of the first pointz0
- z coordinate of the first pointx1
- x coordinate of the second pointy1
- y coordinate of the second pointz1
- z coordinate of the second pointx2
- x coordinate of the third pointy2
- y coordinate of the third pointz2
- z coordinate of the third point
-
Triangle3D
-
Triangle3D
Constructs a newTriangle3D
with its points coinciding with the points of the given triangle.- Parameters:
triangle
- the triangle to copy
-
-
Method Details
-
copy
Sets the points of thisTriangle3D
to coincide with points of the given triangle.- Parameters:
triangle
- the triangle to copy
-
set
public void set(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2) Sets the points of the triangle to coincide with the given coordinates.- Parameters:
x0
- x coordinate of the first pointy0
- y coordinate of the first pointz0
- z coordinate of the first pointx1
- x coordinate of the second pointy1
- y coordinate of the second pointz1
- z coordinate of the second pointx2
- x coordinate of the third pointy2
- y coordinate of the third pointz2
- z coordinate of the third point
-
set
-
point
Description copied from interface:Face3D
Returns the point from thisFace3D
with corresponding index. If an invalid index is given, then null is returned. -
center
Constructs a newPoint3D
at the geometric mean of the three points in thisTriangle3D
.- Returns:
- the center of this
Triangle3D
-
normal
Constructs the unit vector normal to the plane of thisTriangle3D
.- Returns:
- the normal to the plane of this
Triangle3D
-
plane
Constructs the the plane of thisTriangle3D
.- Returns:
- the plane of this
Triangle3D
-
isInside
Test whether the given point is inside the area of thisTriangle3D
.- Parameters:
p
- the given point- Returns:
- true if inside or false if outside
-
distanceFromEdge
Computes the minimum distance of the given point from the edges of thisTriangle3D
.- Parameters:
p
- the given point- Returns:
- the signed distance to the
Triangle3D
edges, positive if inside or negative if outside
-
intersection
Description copied from interface:Face3D
Finds the intersections of the given infinite line with thisFace3D
. If intersections are found they will be appended to the given list. The return value will indicate the number of intersections that were found.- Specified by:
intersection
in interfaceFace3D
- Parameters:
line
- the infinite lineintersections
- the list to store the intersections in- Returns:
- the number of intersections found
-
intersectionRay
Description copied from interface:Face3D
Finds the intersections of the given ray with thisFace3D
. If intersections are found they will be appended to the given list. The return value will indicate the number of intersections that were found.- Specified by:
intersectionRay
in interfaceFace3D
- Parameters:
line
- the rayintersections
- the list to store the intersections in- Returns:
- the number of intersections found
-
intersectionSegment
Description copied from interface:Face3D
Finds the intersections of the given line segment with thisFace3D
. If intersections are found they will be appended to the given list. The return value will indicate the number of intersections that were found.- Specified by:
intersectionSegment
in interfaceFace3D
- Parameters:
line
- the line segmentintersections
- the list to store the intersections in- Returns:
- the number of intersections found
-
translateXYZ
public void translateXYZ(double x, double y, double z) Description copied from interface:Transformable
Translates this object linearly by the amounts specified.- Specified by:
translateXYZ
in interfaceTransformable
- Parameters:
x
- amount to translate along the x axisy
- amount to translate along the y axisz
- amount to translate along the z axis
-
rotateX
public void rotateX(double angle) Description copied from interface:Transformable
Rotates this object clockwise around the x axis.- Specified by:
rotateX
in interfaceTransformable
- Parameters:
angle
- rotation angle in radians
-
rotateY
public void rotateY(double angle) Description copied from interface:Transformable
Rotates this object clockwise around the y axis.- Specified by:
rotateY
in interfaceTransformable
- Parameters:
angle
- rotation angle in radians
-
rotateZ
public void rotateZ(double angle) Description copied from interface:Transformable
Rotates this object clockwise around the z axis.- Specified by:
rotateZ
in interfaceTransformable
- Parameters:
angle
- rotation angle in radians
-
show
-
toString
-