com.partnersoft.geometry.xy
Class XyTriangle

java.lang.Object
  extended by com.partnersoft.geometry.xy.XyTriangle
All Implemented Interfaces:
Immutable, XyArea<XyTriangle>, XyShape<XyTriangle>, java.lang.Iterable<XyPoint>

public class XyTriangle
extends java.lang.Object
implements XyArea<XyTriangle>

A triangle in (x, y) space.

Triangles are useful for many reasons other than as another area or shape. Many problems (e.g. bisecting an directional angle) can be expressed as relationships between three points with connecting line segments. And of course much of trigonometry is based on triangle relationships.

Our model of triangle is based on three ordered vertices vertexA, vertexB, and vertexC. You can then derive lineSegmentAB, lineSegmentBC, and lineSegmentCA, angleA, angleB, angleC, and so forth. The terminology for all of these should be painfully obvious.

Much of the math is derived from examples at http://en.wikipedia.org/wiki/Triangle.

Copyright 2008 Partner Software, Inc.

Version:
$Id$
Author:
Paul Reavis, Richard Fay, Rich Stepanski

Constructor Summary
XyTriangle(double xA, double yA, double xB, double yB, double xC, double yC)
          Build a triangle with vertices in the given order.
XyTriangle(XyPoint vertexA, XyPoint vertexB, XyPoint vertexC)
          Build a triangle with vertices in the given order.
 
Method Summary
 boolean contains(XyPoint point)
          Tests if a point is inside this area.
 XyDirection getAngleBisectorDirectionA()
          The direction of the angle bisector for vertex A (going from A to the opposite side).
 XyDirection getAngleBisectorDirectionB()
          The direction of the angle bisector for vertex B (going from B to the opposite side).
 XyDirection getAngleBisectorDirectionC()
          The direction of the angle bisector for vertex C (going from C to the opposite side).
 double getArea()
          Returns the 2-dimensional area covered by this...
 XyBounds getBounds()
          Returns an XyBounds object representing the rectangular extents of this shape.
 XyDeflection getDeflectionABC()
          The deflection of the line segment connecting vertexB to vertexC as compared to the line segment from vertexA to vertexB.
 XyDeflection getDeflectionACB()
          The deflection of the line segment connecting vertexC to vertexB as compared to the line segment from vertexA to vertexC.
 XyDeflection getDeflectionBAC()
          The deflection of the line segment connecting vertexA to vertexC as compared to the line segment from vertexB to vertexA.
 XyDeflection getDeflectionBCA()
          The deflection of the line segment connecting vertex C to vertex A as compared to the line segment from vertexB to vertexC.
 XyDeflection getDeflectionCAB()
          The deflection of the line segment connecting vertexA to vertexC as compared to the line segment from vertexC to vertexA.
 XyDeflection getDeflectionCBA()
          The deflection of the line segment connecting vertexB to vertexA as compared to the line segment from vertexC to vertexB.
 XyDirection getDirectionAB()
          The direction of the line segment connecting vertexA to vertexB.
 XyDirection getDirectionAC()
          The direction of the line segment connecting vertexA to vertexC.
 XyDirection getDirectionBA()
          The direction of the line segment connecting vertexB to vertexA.
 XyDirection getDirectionBC()
          The direction of the line segment connecting vertexB to vertexC.
 XyDirection getDirectionCA()
          The direction of the line segment connecting vertexC to vertexA.
 XyDirection getDirectionCB()
          The direction of the line segment connecting vertexC to vertexB.
 XyAngle getExteriorAngleA()
          The exterior interior angle at vertex A.
 XyAngle getExteriorAngleB()
          The exterior interior angle at vertex B.
 XyAngle getExteriorAngleC()
          The exterior interior angle at vertex C.
 XyAngle getInteriorAngleA()
          The interior angle at vertex A.
 XyAngle getInteriorAngleB()
          The interior angle at vertex B.
 XyAngle getInteriorAngleC()
          The interior angle at vertex C.
 double getLengthAB()
          The length of line segment (side) AB.
 double getLengthBC()
          The length of line segment (side) BC.
 double getLengthCA()
          The length of line segment (side) CA.
 XyLineSegment getLineSegmentAB()
          The line segment connecting vertexA to vertexB.
 XyLineSegment getLineSegmentAC()
          The line segment connecting vertexA to vertexC.
 XyLineSegment getLineSegmentBA()
          The line segment connecting vertexB to vertexA.
 XyLineSegment getLineSegmentBC()
          The line segment connecting vertexB to vertexC.
 XyLineSegment getLineSegmentCA()
          The line segment connecting vertexC to vertexA.
 XyLineSegment getLineSegmentCB()
          The line segment connecting vertexC to vertexB.
 double getPerimeter()
          Returns the total length of the lines and/or curves bounding the area.
 XyVector getVectorAB()
          The vector from vertexA to vertexB.
 XyVector getVectorAC()
          The vector from vertexA to vertexC.
 XyVector getVectorBA()
          The vector from vertexB to vertexA.
 XyVector getVectorBC()
          The vector from vertexB to vertexC.
 XyVector getVectorCA()
          The vector from vertexC to vertexA.
 XyVector getVectorCB()
          The vector from vertexC to vertexB.
 XyPoint getVertexA()
          The first vertex, labeled A.
 XyPoint getVertexB()
          The second vertex, labeled B.
 XyPoint getVertexC()
          The third vertex, labeled C.
 java.util.Iterator<XyPoint> iterator()
           
 XyTriangle scaledBy(double factor)
          Return a scaled version of the shape by multiplying all coordinates by the given factor in both dimensions.
 XyPolygon toPolygon()
          Same as XyArea.toPolygon(XyAngle) with a default angle granularity of 1/60 circle (1 degree, pi/30 radians).
 XyPolygon toPolygon(XyAngle granularity)
          Converts this area to a polygon which approximates it in some fashion.
 XyShape transformedBy(XyTransform transform)
          Transform the shape using the given transform.
 XyTriangle translatedBy(double offsetX, double offsetY)
          Translate the shape by adding all coordinates to the given x and y offsets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XyTriangle

public XyTriangle(XyPoint vertexA,
                  XyPoint vertexB,
                  XyPoint vertexC)
Build a triangle with vertices in the given order.


XyTriangle

public XyTriangle(double xA,
                  double yA,
                  double xB,
                  double yB,
                  double xC,
                  double yC)
Build a triangle with vertices in the given order.

Method Detail

getVertexA

public XyPoint getVertexA()
The first vertex, labeled A.


getVertexB

public XyPoint getVertexB()
The second vertex, labeled B.


getVertexC

public XyPoint getVertexC()
The third vertex, labeled C.


getLineSegmentAB

public XyLineSegment getLineSegmentAB()
The line segment connecting vertexA to vertexB.


getLineSegmentBC

public XyLineSegment getLineSegmentBC()
The line segment connecting vertexB to vertexC.


getLineSegmentCA

public XyLineSegment getLineSegmentCA()
The line segment connecting vertexC to vertexA.


getLineSegmentBA

public XyLineSegment getLineSegmentBA()
The line segment connecting vertexB to vertexA.


getLineSegmentCB

public XyLineSegment getLineSegmentCB()
The line segment connecting vertexC to vertexB.


getLineSegmentAC

public XyLineSegment getLineSegmentAC()
The line segment connecting vertexA to vertexC.


getVectorAB

public XyVector getVectorAB()
The vector from vertexA to vertexB.


getVectorBC

public XyVector getVectorBC()
The vector from vertexB to vertexC.


getVectorCA

public XyVector getVectorCA()
The vector from vertexC to vertexA.


getVectorBA

public XyVector getVectorBA()
The vector from vertexB to vertexA.


getVectorCB

public XyVector getVectorCB()
The vector from vertexC to vertexB.


getVectorAC

public XyVector getVectorAC()
The vector from vertexA to vertexC.


getLengthAB

public double getLengthAB()
The length of line segment (side) AB.


getLengthBC

public double getLengthBC()
The length of line segment (side) BC.


getLengthCA

public double getLengthCA()
The length of line segment (side) CA.


getDirectionAB

public XyDirection getDirectionAB()
The direction of the line segment connecting vertexA to vertexB.


getDirectionBC

public XyDirection getDirectionBC()
The direction of the line segment connecting vertexB to vertexC.


getDirectionCA

public XyDirection getDirectionCA()
The direction of the line segment connecting vertexC to vertexA.


getDirectionAC

public XyDirection getDirectionAC()
The direction of the line segment connecting vertexA to vertexC.


getDirectionBA

public XyDirection getDirectionBA()
The direction of the line segment connecting vertexB to vertexA.


getDirectionCB

public XyDirection getDirectionCB()
The direction of the line segment connecting vertexC to vertexB.


getDeflectionABC

public XyDeflection getDeflectionABC()
The deflection of the line segment connecting vertexB to vertexC as compared to the line segment from vertexA to vertexB.


getDeflectionBCA

public XyDeflection getDeflectionBCA()
The deflection of the line segment connecting vertex C to vertex A as compared to the line segment from vertexB to vertexC.


getDeflectionCAB

public XyDeflection getDeflectionCAB()
The deflection of the line segment connecting vertexA to vertexC as compared to the line segment from vertexC to vertexA.


getDeflectionACB

public XyDeflection getDeflectionACB()
The deflection of the line segment connecting vertexC to vertexB as compared to the line segment from vertexA to vertexC.


getDeflectionBAC

public XyDeflection getDeflectionBAC()
The deflection of the line segment connecting vertexA to vertexC as compared to the line segment from vertexB to vertexA.


getDeflectionCBA

public XyDeflection getDeflectionCBA()
The deflection of the line segment connecting vertexB to vertexA as compared to the line segment from vertexC to vertexB.


getInteriorAngleA

public XyAngle getInteriorAngleA()
The interior angle at vertex A.


getInteriorAngleB

public XyAngle getInteriorAngleB()
The interior angle at vertex B.


getInteriorAngleC

public XyAngle getInteriorAngleC()
The interior angle at vertex C.


getExteriorAngleA

public XyAngle getExteriorAngleA()
The exterior interior angle at vertex A.


getExteriorAngleB

public XyAngle getExteriorAngleB()
The exterior interior angle at vertex B.


getExteriorAngleC

public XyAngle getExteriorAngleC()
The exterior interior angle at vertex C.


getAngleBisectorDirectionA

public XyDirection getAngleBisectorDirectionA()
The direction of the angle bisector for vertex A (going from A to the opposite side).


getAngleBisectorDirectionB

public XyDirection getAngleBisectorDirectionB()
The direction of the angle bisector for vertex B (going from B to the opposite side).


getAngleBisectorDirectionC

public XyDirection getAngleBisectorDirectionC()
The direction of the angle bisector for vertex C (going from C to the opposite side).


contains

public boolean contains(XyPoint point)
Description copied from interface: XyArea
Tests if a point is inside this area.

Specified by:
contains in interface XyArea<XyTriangle>
Parameters:
point - point to test for containment

getArea

public double getArea()
Description copied from interface: XyArea
Returns the 2-dimensional area covered by this... area.

Specified by:
getArea in interface XyArea<XyTriangle>
Returns:
geometric area of this shape

getPerimeter

public double getPerimeter()
Description copied from interface: XyArea
Returns the total length of the lines and/or curves bounding the area.

Specified by:
getPerimeter in interface XyArea<XyTriangle>
Returns:
geometric perimeter of this shape

toPolygon

public XyPolygon toPolygon(XyAngle granularity)
Description copied from interface: XyArea
Converts this area to a polygon which approximates it in some fashion. For example, a circle can be converted to a polygon with enough sides to roughly approximate its shape. Areas consisting of linked line segments can be represented exactly.

The angle parameter allows a certain level of control of the output. Essentially it dictates the minimum angular granularity used to approximate curved paths. For example, a circle would be turned into a polygon by placing points around the circle, separated by the given angle.

Specified by:
toPolygon in interface XyArea<XyTriangle>

toPolygon

public XyPolygon toPolygon()
Description copied from interface: XyArea
Same as XyArea.toPolygon(XyAngle) with a default angle granularity of 1/60 circle (1 degree, pi/30 radians).

Specified by:
toPolygon in interface XyArea<XyTriangle>

getBounds

public XyBounds getBounds()
Description copied from interface: XyShape
Returns an XyBounds object representing the rectangular extents of this shape.

Specified by:
getBounds in interface XyShape<XyTriangle>

scaledBy

public XyTriangle scaledBy(double factor)
Description copied from interface: XyShape
Return a scaled version of the shape by multiplying all coordinates by the given factor in both dimensions. This resulting shape must be of the same class as the original.

Specified by:
scaledBy in interface XyShape<XyTriangle>
Parameters:
factor - scaling factor
Returns:
scaled result

transformedBy

public XyShape transformedBy(XyTransform transform)
Description copied from interface: XyShape
Transform the shape using the given transform. Due to potential distortion the result may be a different type of shape than this one.

Specified by:
transformedBy in interface XyShape<XyTriangle>
Parameters:
transform - affine transform to apply.
Returns:
transformed result

translatedBy

public XyTriangle translatedBy(double offsetX,
                               double offsetY)
Description copied from interface: XyShape
Translate the shape by adding all coordinates to the given x and y offsets. The resulting shape must be of the same class as the original.

Specified by:
translatedBy in interface XyShape<XyTriangle>
Parameters:
offsetX - offset for the x dimension
offsetY - offset for the y dimension
Returns:
offset result

iterator

public java.util.Iterator<XyPoint> iterator()
Specified by:
iterator in interface java.lang.Iterable<XyPoint>