org.jdelaunay.delaunay.geometries
Class DTriangle

java.lang.Object
  extended by org.jdelaunay.delaunay.geometries.Element
      extended by org.jdelaunay.delaunay.geometries.DTriangle
All Implemented Interfaces:
Comparable<DTriangle>

public class DTriangle
extends Element
implements Comparable<DTriangle>

This is the class representing a Triangle in the DelaunayTriangulation. A DTriangle is made of three edges, each edge sharing a point with the other ones. Consequently, a DTriangle can be identified thanks to its edges, or thanks to its associated DPoint instances.

Author:
Adelin Piau, Jean-Yves Martin, Erwan Bocher, Alexis Guéganno

Field Summary
static int PT_NB
           
 
Fields inherited from class org.jdelaunay.delaunay.geometries.Element
WEIGHTED_PROPERTIES
 
Constructor Summary
DTriangle(DEdge e1, DEdge e2, DEdge e3)
          Create a new triangle with the three given edges as a basis.
DTriangle(DPoint p1, DPoint p2, DPoint p3)
          Create a new triangle with three input points.
DTriangle(DTriangle aTriangle)
          Create a DTriangle from another triangle
NB : it doesn't update edges connection - topology is not preserved.
 
Method Summary
 boolean belongsTo(DPoint aPoint)
          Check if the point is an apex of the triangle
 boolean checkTopology()
          Check if triangle topology is correct or not
 int compareTo(DTriangle t)
          Implements the Comparable interface.
 boolean contains(com.vividsolutions.jts.geom.Coordinate c)
          Check if the coordinate is inside the element
 boolean contains(DPoint aPoint)
          Check if the point is inside the element
 void displayObject(Graphics g, int decalageX, int decalageY, double minX, double minY, double scaleX, double scaleY)
          Display the triangle in a JPanel Must be used only when using package drawing
protected  void displayObjectCircles(Graphics g, int decalageX, int decalageY)
          Display the triangle in a JPanel Must be used only when using package drawing
 boolean equals(Object other)
          Used to check if this is equal to other.
 void forceCoherenceWithEdges()
          This method force the link between this and its edges, and ensure that edges are not pointing to duplicates of this triangle.
 DPoint getAlterPoint(DPoint p1, DPoint p2)
          Get the point of the triangle that is not one of the 2 points given in argument.
 double getAngle(int k)
          Retrieve the angle, in degrees, at vertex number k.
 double getArea()
          Compute triangle area
 DPoint getBarycenter()
          Get the barycenter of the triangle as a DPoint
 BoundaryBox getBoundingBox()
          Computed bounding box
 com.vividsolutions.jts.geom.Coordinate getCircumCenter()
          Get the center of the CircumCircle
 Element getCircumCenterContainer()
          Return the triangle of the mesh that contains the center of this DTriangle.
 Element getCircumCenterContainerSafe()
          Return the triangle of the mesh that contains the center of this DTriangle.
 DEdge getContainingEdge(DPoint pt)
          Get the edge that contains pt (if any, and the first found if pt is an apex)
 DPoint getCounterSteepestIntersection(DPoint dp)
          Compute the intersection point according to the vector opposite to the steepest vector.
 DEdge getEdge(int i)
          Get the ith edge i must be equal to 0, 1 or 2.
protected  DEdge getEdgeFromPoints(DPoint p1, DPoint p2)
          Get the edge of the triangle that includes the two point
 int getEdgeIndex(DEdge ed)
          Get the index of the edge in the triangle.
 DEdge[] getEdges()
          Return the edges that form this triangle in an array.
 DEdge getLastEdge(DEdge e1, DEdge e2)
          Get the last edge that form, with e1 and e2, this triangle.
 DPoint getLeftMost()
          Get the leftmost point of this triangle.
 double getMaxAngle()
          Return the maximal angle of this triangle.
 double getMinAngle()
          Return the maximal angle og this triangle.
 double getMinSquareDistance(DPoint pt)
          Return the square of the minimal distance between pt and the apex of this triangle.
 DPoint getNormalVector()
          Get the normal vector to this triangle, of length 1.
 DEdge getOppositeEdge(DPoint pt)
          Return the edge that is not linked to pt, or null if pt is not a point of this triangle.
 DPoint getOppositePoint(DEdge ed)
          Get the point of the triangle that does not belong to the edge
 DPoint getPoint(int i)
          Get the ith point. i must be equal to 0, 1 or 2.
 List<DPoint> getPoints()
          Get a list of points containing the DPoint that define this triangle.
 double getRadius()
          Get the radius of the CircumCircle
 double getSlope()
          Get the slope of this DTriangle.
 double getSlopeAspect()
          Compute the azimut of the triangle in degrees between north and steeepest vector.
 double getSlopeInDegree()
          get the slope of this DTriangle, in degrees.
 double getSlopeInPercent()
          Compute the slope of the triangle in percent
 DPoint getSteepestIntersectionPoint(DPoint dPoint)
          Compute the intersection point according the steepest vector.
 DPoint getSteepestVector()
          Get the vector with the highest down slope in the plan associated to this triangle.
 int hashCode()
           
 int inCircle(DPoint aPoint)
          Check if the aPoint is in or on the circumcircle of this triangle.
 double interpolateZ(DPoint aPoint)
          Get Z value of a specific point in the triangle
 boolean isCloser(DPoint pt, double threshold)
          Returns true if the minimal distance between pt and one of the apex is smaller than threshold.
 boolean isEdgeOf(DEdge ed)
          Returns true if ed is equals to one of the edges that form this triangle.
 boolean isFlatSlope()
          Check if the triangle is flat or not.
 boolean isInside(DPoint aPoint)
          Check if the point is inside the triangle
 boolean isOnAnEdge(DPoint pt)
          Determines if pt lies on one of the edges of this triangle.
 boolean isProcessed()
          If true, the triangle is supposed to be in the structure that stores the already processed triangles.
 boolean isSeenForFlatRemoval()
          check if this triangle has already been encountered (and marked if flat) during the flat removal operation.
 boolean isTopoOrientedToEdge(DEdge ed)
          Returns true if the triangle is turned toward the edge ed.
 void recomputeCenter()
          Recompute the center of the circle that joins the ptNb points : the CircumCenter
 Element searchPointContainer(DPoint pt)
          This method recursively search for pt in the mesh.
 boolean setEdge(int i, DEdge anEdge)
          Set the ith edge.
 void setProcessed(boolean pro)
          Set the processed attribute.
 void setSeenForFlatRemoval(boolean seenForFlatRemoval)
          Set the value of the seenForFlatRemoval attribute, that is used to process flat triangles only once during the flat tiangles removal operation.
 boolean sharedByTwoEdge(DPoint pt)
          test if pt is an apex of this triangle.
 double softInterpolateZ(DPoint aPoint)
          Get Z value of a specific point in the triangle Take into account triangles connected to the edge
 String toString()
          Gives a rperesentation of this triangle as a String.
 
Methods inherited from class org.jdelaunay.delaunay.geometries.Element
addProperty, getExternalGID, getGID, getHeight, getMaxWeight, getProperty, hasProperty, removeProperties, setExternalGID, setGID, setHeight, setProperty
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PT_NB

public static final int PT_NB
See Also:
Constant Field Values
Constructor Detail

DTriangle

public DTriangle(DEdge e1,
                 DEdge e2,
                 DEdge e3)
          throws DelaunayError
Create a new triangle with the three given edges as a basis.

An integrity check is processed while building the triangle. This constructor is the best way to ensure that already existing edges will be linked to the good triangles, and that ther won't be any edge duplication in the data structures.

Parameters:
e1 -
e2 -
e3 -
Throws:
DelaunayError - If there is at least two edges that don't share exactly a point.

DTriangle

public DTriangle(DPoint p1,
                 DPoint p2,
                 DPoint p3)
          throws DelaunayError
Create a new triangle with three input points.

Parameters:
p1 -
p2 -
p3 -
Throws:
DelaunayError

DTriangle

public DTriangle(DTriangle aTriangle)
Create a DTriangle from another triangle
NB : it doesn't update edges connection - topology is not preserved.

Parameters:
aTriangle -
Method Detail

getPoints

public final List<DPoint> getPoints()
Get a list of points containing the DPoint that define this triangle.

This method is consistent with getPoint, ie getPoints().get(i)==getPoint(i).

Returns:
the apex of the triangle, in a list.

getPoint

public final DPoint getPoint(int i)
Get the ith point. i must be equal to 0, 1 or 2.

This method is consistent with getPoints, ie getPoints().get(i)==getPoint(i).

Parameters:
i -
Returns:
aPoint On of the apex if i = 0, 1 or 2, null otherwise.

getEdge

public final DEdge getEdge(int i)
Get the ith edge i must be equal to 0, 1 or 2.

Parameters:
i -
Returns:
anEdge

getEdges

public final DEdge[] getEdges()
Return the edges that form this triangle in an array.

This method is consistent with getEdge(i), ie getEdge(i)==getEdges()[i]

Returns:
The edges in an array.

getEdgeIndex

public final int getEdgeIndex(DEdge ed)
Get the index of the edge in the triangle.

Parameters:
ed -
Returns:
The index of the edge in its array of edges, -1 if ed is not an edge of this triangle.

setEdge

public final boolean setEdge(int i,
                             DEdge anEdge)
Set the ith edge. If i<0 or i>2, this method returns quietly without doing anything.

Parameters:
i -
anEdge -
Returns:
true if anEdge has been successfully inserted, false otherwise.

getRadius

public final double getRadius()
Get the radius of the CircumCircle

Returns:
radius

getCircumCenter

public final com.vividsolutions.jts.geom.Coordinate getCircumCenter()
Get the center of the CircumCircle

Returns:
The circumcenter of the triangle, as a JTS Coordinate.

isSeenForFlatRemoval

public final boolean isSeenForFlatRemoval()
check if this triangle has already been encountered (and marked if flat) during the flat removal operation.

Returns:
true if this triangle has already been encountered.

setSeenForFlatRemoval

public final void setSeenForFlatRemoval(boolean seenForFlatRemoval)
Set the value of the seenForFlatRemoval attribute, that is used to process flat triangles only once during the flat tiangles removal operation.

Parameters:
seenForFlatRemoval -

isProcessed

public final boolean isProcessed()
If true, the triangle is supposed to be in the structure that stores the already processed triangles.

Returns:

setProcessed

public final void setProcessed(boolean pro)
Set the processed attribute.

Parameters:
pro -

getBoundingBox

public final BoundaryBox getBoundingBox()
Description copied from class: Element
Computed bounding box

Specified by:
getBoundingBox in class Element
Returns:
The boundary box of this element.

getLeftMost

public final DPoint getLeftMost()
Get the leftmost point of this triangle.

Returns:
the leftmost point of this triangle.

getLastEdge

public final DEdge getLastEdge(DEdge e1,
                               DEdge e2)
Get the last edge that form, with e1 and e2, this triangle. If e1 or e2 do not belong to this triangle, return null.

Parameters:
e1 -
e2 -
Returns:
the edge of the triangle that is not e1 or e2. Null if e1 or e2 is not an edge of the triangle.

contains

public final boolean contains(DPoint aPoint)
Description copied from class: Element
Check if the point is inside the element

Specified by:
contains in class Element
Returns:
bool

contains

public final boolean contains(com.vividsolutions.jts.geom.Coordinate c)
                       throws DelaunayError
Description copied from class: Element
Check if the coordinate is inside the element

Specified by:
contains in class Element
Returns:
bool
Throws:
DelaunayError

isOnAnEdge

public final boolean isOnAnEdge(DPoint pt)
Determines if pt lies on one of the edges of this triangle.

Parameters:
pt -
Returns:
true if it does.

recomputeCenter

public final void recomputeCenter()
                           throws DelaunayError
Recompute the center of the circle that joins the ptNb points : the CircumCenter

Throws:
DelaunayError

inCircle

public final int inCircle(DPoint aPoint)
Check if the aPoint is in or on the circumcircle of this triangle.

Parameters:
aPoint -
Returns:
position :
* 0 = outside
* 1 = inside
* 2 = on the circle

isInside

public final boolean isInside(DPoint aPoint)
Check if the point is inside the triangle

Parameters:
aPoint -
Returns:
isInside

interpolateZ

public final double interpolateZ(DPoint aPoint)
Get Z value of a specific point in the triangle

Parameters:
aPoint -
Returns:
ZValue

softInterpolateZ

public final double softInterpolateZ(DPoint aPoint)
Get Z value of a specific point in the triangle Take into account triangles connected to the edge

Parameters:
aPoint -
Returns:
ZValue

getArea

public final double getArea()
Compute triangle area

Returns:
area

getNormalVector

public final DPoint getNormalVector()
                             throws DelaunayError
Get the normal vector to this triangle, of length 1.

Returns:
Get the vector normal to the triangle.
Throws:
DelaunayError

getSteepestVector

public final DPoint getSteepestVector()
                               throws DelaunayError
Get the vector with the highest down slope in the plan associated to this triangle.

Returns:
return the steepest vector.
Throws:
DelaunayError

getSlope

public final double getSlope()
                      throws DelaunayError
Get the slope of this DTriangle. Be careful, as the returned value will be negative

Returns:
the slope of this triangle, in rads
Throws:
DelaunayError

getSlopeInDegree

public final double getSlopeInDegree()
                              throws DelaunayError
get the slope of this DTriangle, in degrees. Be careful, as the returned value will be negative.

Returns:
the slope, in degrees.
Throws:
DelaunayError

getMinAngle

public final double getMinAngle()
Return the maximal angle og this triangle.

Returns:
the minimal angle of this triangle.

getMaxAngle

public final double getMaxAngle()
Return the maximal angle of this triangle.

Returns:
maxAngle

checkTopology

public final boolean checkTopology()
Check if triangle topology is correct or not

Returns:
correct

sharedByTwoEdge

public final boolean sharedByTwoEdge(DPoint pt)
test if pt is an apex of this triangle. It must be an extremity of two of the edges, and must not be an extremity of the last one.

Parameters:
pt -
Returns:
true if pt is an apex of the triangle.

isFlatSlope

public final boolean isFlatSlope()
Check if the triangle is flat or not. In other words, this method checks if the 3 points have the same Z.

Returns:
isFlat

getOppositePoint

public final DPoint getOppositePoint(DEdge ed)
Get the point of the triangle that does not belong to the edge

Parameters:
ed -
Returns:
alterPoint

getOppositeEdge

public final DEdge getOppositeEdge(DPoint pt)
Return the edge that is not linked to pt, or null if pt is not a point of this triangle.

Parameters:
pt -

getAlterPoint

public final DPoint getAlterPoint(DPoint p1,
                                  DPoint p2)
Get the point of the triangle that is not one of the 2 points given in argument. If one of these argument is not part of this triangle, this method will return null.

Parameters:
p1 -
p2 -
Returns:
alterPoint

getEdgeFromPoints

protected final DEdge getEdgeFromPoints(DPoint p1,
                                        DPoint p2)
Get the edge of the triangle that includes the two point

Parameters:
p1 -
p2 -
Returns:
alterEdge

belongsTo

public final boolean belongsTo(DPoint aPoint)
Check if the point is an apex of the triangle

Parameters:
aPoint -
Returns:
belongs

getBarycenter

public final DPoint getBarycenter()
                           throws DelaunayError
Get the barycenter of the triangle as a DPoint

Returns:
isFlat
Throws:
DelaunayError

toString

public final String toString()
Gives a rperesentation of this triangle as a String.

Overrides:
toString in class Object
Returns:
Triangle "+gid+": ["+getPoint(0).toString()+", "+getPoint(1).toString()+", "+getPoint(2).toString()+"]

displayObject

public final void displayObject(Graphics g,
                                int decalageX,
                                int decalageY,
                                double minX,
                                double minY,
                                double scaleX,
                                double scaleY)
Display the triangle in a JPanel Must be used only when using package drawing

Parameters:
g -
decalageX -
decalageY -
minX -
minY -
scaleX -
scaleY -

displayObjectCircles

protected final void displayObjectCircles(Graphics g,
                                          int decalageX,
                                          int decalageY)
Display the triangle in a JPanel Must be used only when using package drawing

Parameters:
g -
decalageX -
decalageY -

equals

public final boolean equals(Object other)
Used to check if this is equal to other. This and other are equal if and only if other is an instance of DTriangle and their points are the same (whatever their order in the triangle).

Overrides:
equals in class Object
Parameters:
other -
Returns:
true if this and other are equal

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

compareTo

public final int compareTo(DTriangle t)
Implements the Comparable interface. The triangles will be sorted according the middle of their bounding box. As we work on a triangulation where triangles' intersection can only be an edge, a point or void, the Bounding boxes are unique. BE CAREFUL : this method is not consistent with equals ! We are making a comparison on the bounding box of two triangles, they could be equal even if the triangle are different !!!

Specified by:
compareTo in interface Comparable<DTriangle>
Parameters:
t -
Returns:
-1, 0 or 1, using the point comparison on the center of the bounding boxes

getAngle

public final double getAngle(int k)
Retrieve the angle, in degrees, at vertex number k.

Parameters:
k -
Returns:
The angle at the ith point.

getSlopeInPercent

public final double getSlopeInPercent()
                               throws DelaunayError
Compute the slope of the triangle in percent

Returns:
the slope of the triangle, in percent.
Throws:
DelaunayError

getSlopeAspect

public final double getSlopeAspect()
                            throws DelaunayError
Compute the azimut of the triangle in degrees between north and steeepest vector. Aspect is measured clockwise in degrees from 0, due north, to 360, again due north, coming full circle.

Returns:
the aspect of the slope of this triangle.
Throws:
DelaunayError

isTopoOrientedToEdge

public final boolean isTopoOrientedToEdge(DEdge ed)
                                   throws DelaunayError
Returns true if the triangle is turned toward the edge ed.

Parameters:
ed -
Returns:
true if this is pouring into ed.
Throws:
DelaunayError

getSteepestIntersectionPoint

public final DPoint getSteepestIntersectionPoint(DPoint dPoint)
                                          throws DelaunayError
Compute the intersection point according the steepest vector. We assume that the point is in the Triangle

Returns:
DPoint
Throws:
DelaunayError

getCounterSteepestIntersection

public final DPoint getCounterSteepestIntersection(DPoint dp)
                                            throws DelaunayError
Compute the intersection point according to the vector opposite to the steepest vector. If dp is outside the triangle, we return null.

Parameters:
dp -
Returns:
The point pt of the triangle's boundary for which (dp pt) is colinear to the steepest vector.
Throws:
DelaunayError

getCircumCenterContainer

public final Element getCircumCenterContainer()
                                       throws DelaunayError
Return the triangle of the mesh that contains the center of this DTriangle.

Returns:
The DTriangle that contains the circumcenter of this. The last DEdge seen, if the circumcenter is not in the mesh.
Throws:
DelaunayError

getCircumCenterContainerSafe

public final Element getCircumCenterContainerSafe()
                                           throws DelaunayError
Return the triangle of the mesh that contains the center of this DTriangle.

Returns:
The DTriangle that contains the circumcenter of this.
The last DEdge seen, if the circumcenter is not in the mesh.
null if a constraint is crossed while searching for the circumcenter.
Throws:
DelaunayError

searchPointContainer

public final Element searchPointContainer(DPoint pt)
                                   throws DelaunayError
This method recursively search for pt in the mesh. If it's in this, this is returned. Else, we search in the adjacent triangles.

Parameters:
pt -
Returns:
The triangle that contains the triangle, or the last edge visited if the point is outside the mesh.
Throws:
DelaunayError

getContainingEdge

public final DEdge getContainingEdge(DPoint pt)
Get the edge that contains pt (if any, and the first found if pt is an apex)

Parameters:
pt -
Returns:
The containing edge, if any, null otherwise.

isEdgeOf

public final boolean isEdgeOf(DEdge ed)
Returns true if ed is equals to one of the edges that form this triangle.

Parameters:
ed -
Returns:
true if ed is an edge of this.

getMinSquareDistance

public final double getMinSquareDistance(DPoint pt)
Return the square of the minimal distance between pt and the apex of this triangle.

Parameters:
pt -
Returns:
the square of the minimal distance between pt and the apex of this triangle.

isCloser

public final boolean isCloser(DPoint pt,
                              double threshold)
Returns true if the minimal distance between pt and one of the apex is smaller than threshold.

Parameters:
pt -
threshold -
Returns:
the minimal distance between pt and one of the apex is smaller than threshold.

forceCoherenceWithEdges

public final void forceCoherenceWithEdges()
This method force the link between this and its edges, and ensure that edges are not pointing to duplicates of this triangle.



Copyright © 2014 IRSTV CNRS-FR-2488. All Rights Reserved.