com.quinncurtis.chart3djava
Class Polygon3D

java.lang.Object
  extended by com.quinncurtis.chart3djava.Polygon3D
All Implemented Interfaces:
java.lang.Comparable

public class Polygon3D
extends java.lang.Object
implements java.lang.Comparable

A 3D polygon class.


Field Summary
static int MAX_VALUE_SORT
          Specifies polygon sort using max values of polygon vertices.
static int MEAN_VALUE_SORT
          Specifies polygon sort using mean values of polygon vertices.
static int MIN_VALUE_SORT
          Specifies polygon sort using minimum values of polygon vertices.
 
Constructor Summary
Polygon3D()
          The default constructor.
Polygon3D(ChartPoint3D[] newpoints)
          Constructor initializes a polygon.
Polygon3D(ChartPoint3D[] newpoints, ChartAttribute outsideattrib)
          Constructor initializes a polygon.
Polygon3D(int size)
          Constructor initializes a polygon with a fixed number of vertices, but with all point values set to (0,0,0).
Polygon3D(PhysicalCoordinates transform)
          Constructor initializes the coordinate system associated with the polygon.
Polygon3D(PhysicalCoordinates transform, ChartAttribute outsideattrib)
          Constructor initializes a polygon.
Polygon3D(PhysicalCoordinates transform, ChartPoint3D[] newpoints, ChartAttribute outsideattrib)
          Constructor initializes a polygon.
Polygon3D(PhysicalCoordinates transform, ChartPoint3D[] newpoints, int[] pointindices, ChartAttribute outsideattrib)
          Constructor initializes a polygon.
Polygon3D(PhysicalCoordinates transform, ChartPoint3D p1, ChartPoint3D p2, ChartAttribute outsideattrib)
          Constructor initializes a polyline as a simple 2-point line.
Polygon3D(PhysicalCoordinates transform, double[] x, double[] y, double[] z, ChartAttribute outsideattrib)
          Constructor initializes a polygon.
Polygon3D(PhysicalCoordinates transform, DoubleArray x, DoubleArray y, DoubleArray z, ChartAttribute outsideattrib)
          Constructor initializes a polygon.
Polygon3D(Polygon3D source)
          Constructor initializes the polygon as acopy of a another Polygon3D object.
 
Method Summary
 int addLine(ChartPoint3D p1, ChartPoint3D p2)
          Add a pair of points to the polygon.
 int addLine(double x1, double y1, double z1, double x2, double y2, double z2)
          Add a pair of points to the polygon.
 int addVertex(ChartPoint3D newpoint)
          Add a new vertex to the polygon.
 int addVertex(double x, double y, double z)
          Add a new vertex to the polygon.
 int addVertices(ChartPoint3D[] newpoints, ChartAttribute outsideattrib)
          Add an array of new vertices to the polygon.
 void clampPolygonToCoordinateLimits()
          Clamp the polygon vertex values to the coordinate systems limits.
 void clear()
          Resets the polygon back to it's default (empty) state.
 java.lang.Object clone()
          Returns an object that is a clone of this object.
 void closePolygon()
          Checks to see if the last point matches the first point in the polygon, and adds a point if it isn't.
 int compareTo(java.lang.Object obj)
          CompareTo method require by IComparable interface.
static Polygon3D convertForStepMode(Polygon3D polygon, int stepmode)
          Convert a polygon to a "stepped" version of the same polygon.
 void copy(Polygon3D source)
          Copies the source object.
 int count()
          Get the number of vertices.
 void draw(java.awt.Graphics2D g2)
          The draw function for the class.
static void draw(java.awt.Graphics2D g2, Polygon3D polygon)
          A static routine that draws a Polygon3D object.
 PhysicalCoordinates getCoordinateSystem()
          Get the objects coordinate system.
 int getCoordinateType()
          Get the coordinate system type of the polygon (SCREEN_POS, DEV_POS, PHYS_POS).
 ChartPoint3D[] getCopyOfVertices()
          Returns a copy of the vertices of the polygon as an array of ChartPoint3D objects.
 int getDataPointIndex()
          Get data point index of the polygon.
 ChartPoint3D getElement(int index)
          This accessor is the indexer for the class and get/sets the value of an individual vertex in the polygon.
 boolean getEnableCullRearFacing()
          Returns true if culling of rear facing polygons is enabled.
 boolean getEnablePolygon()
          Returns true to enable the polygon.
 int getGroupIndex()
          Get the group index of the polygon.
 ChartAttribute getInsideAttribute()
          Get inside color attribute of the object.
 double getMaxValue(int axis)
          Returns the maximum value of the polygon vertices for a given axis.
 double getMeanValue(int axis)
          Returns the mean value of the polygon vertices for a given axis.
 double getMinValue(int axis)
          Returns the minimum value of the polygon vertices for a given axis.
 ChartAttribute getOutsideAttribute()
          Get outside color attribute of the object.
 Point3DArray getPointArray()
          Get the pointArray object holding the point list that define the polygon.
 Polygon3D getTransformPolygon()
          Transforms the polygon to screen coordinates and return the result as a new Polygon3D object.
 ChartPoint3D[] getVertices()
          Returns the vertices of the polygon as an array of ChartPoint3D objects.
 int insertAt(int index, ChartPoint3D newpoint)
          Inserts an object at the specified index.
 boolean isClosedPolygon()
          Returns true if the polyon is a closed, rather than just a polyline.
 void markPolygonIndices(int datapoint, int group)
          Save the polygon data point and group indices.
static void polygonTransform3D(Polygon3D polygon, Transform3D transform)
          Static routine transform the polygon using the specified Transform3D object.
 int removeAt(int index)
          Remove an object at the specified index.
 void reset()
          Resets the polygon back to it's default (empty) state.
 void reversePolygon()
          Reverses the drawing order of the polygon
 void scalePolygon(ChartPoint3D scalef, ChartPoint3D offset)
          Apply an mx + b scaling to each point.
 void setCoordinateSystem(PhysicalCoordinates value)
          Set the objects coordinate system.
 void setCoordinateType(int value)
          Set the coordinate system type of the polygon (SCREEN_POS, DEV_POS, PHYS_POS).
 void setCopyVertices(ChartPoint3D[] newpoints)
          Sets the vertices of the polygon, making a copy of each point.
 void setDataPointIndex(int value)
          Set data point index of the polygon.
 void setElement(int index, ChartPoint3D value)
          This accessor is the indexer for the class and get/sets the value of an individual vertex in the polygon.
 void setEnableCullRearFacing(boolean value)
          Set to true to enable the culling of rear facing polygons.
 void setEnablePolygon(boolean value)
          Set to true to enable the polygon.
 void setGroupIndex(int value)
          Set the group index of the polygon.
 void setInsideAttribute(ChartAttribute value)
          Set inside color attribute of the object.
 void setOutsideAttribute(ChartAttribute value)
          Set outside color attribute of the object.
 void setVertices(ChartPoint3D[] newpoints)
          Sets the vertices of the polygon.
 void setVertices(ChartPoint3D[] newpoints, ChartAttribute outsideattrib)
          Sets the vertices and attribute of the polygon.
 void setVertices(DoubleArray x, DoubleArray y, DoubleArray z, ChartAttribute outsideattrib)
          Sets the vertices and attribute of the polygon.
 boolean testPoint(double x, double y)
          Test to see if a screen coordinates point is in the region of the transformed polygon.
 void transformPolygon()
          Transform the polygon to Screen coordinates.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MEAN_VALUE_SORT

public static final int MEAN_VALUE_SORT
Specifies polygon sort using mean values of polygon vertices.

See Also:
Constant Field Values

MAX_VALUE_SORT

public static final int MAX_VALUE_SORT
Specifies polygon sort using max values of polygon vertices.

See Also:
Constant Field Values

MIN_VALUE_SORT

public static final int MIN_VALUE_SORT
Specifies polygon sort using minimum values of polygon vertices.

See Also:
Constant Field Values
Constructor Detail

Polygon3D

public Polygon3D(PhysicalCoordinates transform)
Constructor initializes the coordinate system associated with the polygon.

Parameters:
transform - The coordinate system associated with the polygon.

Polygon3D

public Polygon3D()
The default constructor.


Polygon3D

public Polygon3D(Polygon3D source)
Constructor initializes the polygon as acopy of a another Polygon3D object.

Parameters:
source - The source polygon.

Polygon3D

public Polygon3D(PhysicalCoordinates transform,
                 ChartPoint3D[] newpoints,
                 int[] pointindices,
                 ChartAttribute outsideattrib)
Constructor initializes a polygon.

Parameters:
transform - The coordinate system associated with the polygon.
newpoints - An array of Point3D objects used to initialize the polygon.
pointindices - An array of indices into the newpoints array, forming the polygon.
outsideattrib - The outside color attribute of the polygon.

Polygon3D

public Polygon3D(PhysicalCoordinates transform,
                 ChartPoint3D[] newpoints,
                 ChartAttribute outsideattrib)
Constructor initializes a polygon.

Parameters:
transform - The coordinate system associated with the polygon.
newpoints - An array of ChartPoint3D objects used to initialize the polygon.
outsideattrib - The outside color attribute of the polygon.

Polygon3D

public Polygon3D(ChartPoint3D[] newpoints,
                 ChartAttribute outsideattrib)
Constructor initializes a polygon.

Parameters:
newpoints - An array of ChartPoint3D objects used to initialize the polygon.
outsideattrib - The outside color attribute of the polygon.

Polygon3D

public Polygon3D(ChartPoint3D[] newpoints)
Constructor initializes a polygon.

Parameters:
newpoints - An array of ChartPoint3D objects used to initialize the polygon.

Polygon3D

public Polygon3D(int size)
Constructor initializes a polygon with a fixed number of vertices, but with all point values set to (0,0,0).

Parameters:
size - The number of vertices in the polygon.

Polygon3D

public Polygon3D(PhysicalCoordinates transform,
                 DoubleArray x,
                 DoubleArray y,
                 DoubleArray z,
                 ChartAttribute outsideattrib)
Constructor initializes a polygon.

Parameters:
transform - The coordinate system associated with the polygon.
x - An array of x-values used to initialize the polygon.
y - An array of y-values used to initialize the polygon.
z - An array of z-values used to initialize the polygon.
outsideattrib - The outside color attribute of the polygon.

Polygon3D

public Polygon3D(PhysicalCoordinates transform,
                 double[] x,
                 double[] y,
                 double[] z,
                 ChartAttribute outsideattrib)
Constructor initializes a polygon.

Parameters:
transform - The coordinate system associated with the polygon.
x - An array of x-values used to initialize the polygon.
y - An array of y-values used to initialize the polygon.
z - An array of z-values used to initialize the polygon.
outsideattrib - The outside color attribute of the polygon.

Polygon3D

public Polygon3D(PhysicalCoordinates transform,
                 ChartAttribute outsideattrib)
Constructor initializes a polygon.

Parameters:
transform - The coordinate system associated with the polygon.
outsideattrib - The outside color attribute of the polygon.

Polygon3D

public Polygon3D(PhysicalCoordinates transform,
                 ChartPoint3D p1,
                 ChartPoint3D p2,
                 ChartAttribute outsideattrib)
Constructor initializes a polyline as a simple 2-point line.

Parameters:
transform - The coordinate system associated with the polygon.
p1 - The first point of the line.
p2 - The second point of the line.
outsideattrib - The outside color attribute of the polygon.
Method Detail

compareTo

public int compareTo(java.lang.Object obj)
CompareTo method require by IComparable interface.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - sort object.
Returns:
Returns 1 if value of this.x greater o.x, 0 if equal, -1 if this.x less than o.x

transformPolygon

public void transformPolygon()
Transform the polygon to Screen coordinates.


polygonTransform3D

public static void polygonTransform3D(Polygon3D polygon,
                                      Transform3D transform)
Static routine transform the polygon using the specified Transform3D object.

Parameters:
transform - The Transform3D associated with the polygon.
polygon - The polygon to transform.

getTransformPolygon

public Polygon3D getTransformPolygon()
Transforms the polygon to screen coordinates and return the result as a new Polygon3D object.

Returns:
Returns a Polygon3D object.

setVertices

public void setVertices(ChartPoint3D[] newpoints,
                        ChartAttribute outsideattrib)
Sets the vertices and attribute of the polygon.

Parameters:
newpoints - An array of points.
outsideattrib - The color attribute for the outside of the polygon.

setVertices

public void setVertices(DoubleArray x,
                        DoubleArray y,
                        DoubleArray z,
                        ChartAttribute outsideattrib)
Sets the vertices and attribute of the polygon.

Parameters:
x - An array of the x-values of the polygon.
y - An array of the y-values of the polygon.
z - An array of the z-values of the polygon.
outsideattrib - The color attribute for the outside of the polygon.

setVertices

public void setVertices(ChartPoint3D[] newpoints)
Sets the vertices of the polygon.

Parameters:
newpoints - An array of points.

setCopyVertices

public void setCopyVertices(ChartPoint3D[] newpoints)
Sets the vertices of the polygon, making a copy of each point.

Parameters:
newpoints - An array of points.

clear

public void clear()
Resets the polygon back to it's default (empty) state.


reset

public void reset()
Resets the polygon back to it's default (empty) state.


closePolygon

public void closePolygon()
Checks to see if the last point matches the first point in the polygon, and adds a point if it isn't.


copy

public void copy(Polygon3D source)
Copies the source object.

Parameters:
source - The source object.

clone

public java.lang.Object clone()
Returns an object that is a clone of this object.

Overrides:
clone in class java.lang.Object
Returns:
Returns a clone of this object.

addVertex

public int addVertex(ChartPoint3D newpoint)
Add a new vertex to the polygon.

Parameters:
newpoint - The point to add.
Returns:
Returns the current number of points in the polygon.

addVertex

public int addVertex(double x,
                     double y,
                     double z)
Add a new vertex to the polygon.

Parameters:
x - The x-value of the point to add.
y - The y-value of the point to add.
z - The z-value of the point to add.
Returns:
Returns the current number of points in the polygon.

addVertices

public int addVertices(ChartPoint3D[] newpoints,
                       ChartAttribute outsideattrib)
Add an array of new vertices to the polygon.

Parameters:
newpoints - Ann array of ChartPoint3D objects to add to the polygon.
outsideattrib - The color attribute of the outside of the polygon.
Returns:
Returns the current number of points in the polygon.

addLine

public int addLine(ChartPoint3D p1,
                   ChartPoint3D p2)
Add a pair of points to the polygon.

Parameters:
p1 - The first of the two points to add.
p2 - The second of the two points to add.
Returns:
Returns the current number of points in the polygon.

addLine

public int addLine(double x1,
                   double y1,
                   double z1,
                   double x2,
                   double y2,
                   double z2)
Add a pair of points to the polygon.

Parameters:
x1 - The x-value of the first point to add.
y1 - The y-value of the first point to add.
z1 - The z-value of the first point to add.
x2 - The x-value of the second point to add.
y2 - The y-value of the second point to add.
z2 - The z-value of the second point to add.
Returns:
Returns the current number of points in the polygon.

insertAt

public int insertAt(int index,
                    ChartPoint3D newpoint)
Inserts an object at the specified index.

Parameters:
index - Insert new point at the index element.
newpoint - The new point to insert at index.
Returns:
Returns the current object count.

removeAt

public int removeAt(int index)
Remove an object at the specified index.

Parameters:
index - Delete point at the index element.
Returns:
Returns the current object count.

getVertices

public ChartPoint3D[] getVertices()
Returns the vertices of the polygon as an array of ChartPoint3D objects.

Returns:
Returns the vertices of the polygon as an array of ChartPoint3D objects.

getCopyOfVertices

public ChartPoint3D[] getCopyOfVertices()
Returns a copy of the vertices of the polygon as an array of ChartPoint3D objects.

Returns:
Returns a copy of the vertices of the polygon as an array of ChartPoint3D objects.

markPolygonIndices

public void markPolygonIndices(int datapoint,
                               int group)
Save the polygon data point and group indices.

Parameters:
datapoint - The data point index of the polygon.
group - The group index of the polygon.

reversePolygon

public void reversePolygon()
Reverses the drawing order of the polygon


scalePolygon

public void scalePolygon(ChartPoint3D scalef,
                         ChartPoint3D offset)
Apply an mx + b scaling to each point.

Parameters:
scalef - The scale factor to apply to each point.
offset - The offset to apply to each point.

testPoint

public boolean testPoint(double x,
                         double y)
Test to see if a screen coordinates point is in the region of the transformed polygon.

Parameters:
x - The x-value of the test point.
y - The y-value of the test point.
Returns:
Returns true if a screen coordinates point is in the region of the transformed polygon.

getMeanValue

public double getMeanValue(int axis)
Returns the mean value of the polygon vertices for a given axis.

Parameters:
axis - The axis id (X_AXIS, Y_AXIS, Z_AXIS).
Returns:
Returns the mean value of the polygon vertices.

clampPolygonToCoordinateLimits

public void clampPolygonToCoordinateLimits()
Clamp the polygon vertex values to the coordinate systems limits.


convertForStepMode

public static Polygon3D convertForStepMode(Polygon3D polygon,
                                           int stepmode)
Convert a polygon to a "stepped" version of the same polygon.

Parameters:
polygon - The source Polygon3D object.
stepmode - The desired step mode (NO_STEP, STEP_END, STEP_START).
Returns:
Returns the converted polygon.

getMinValue

public double getMinValue(int axis)
Returns the minimum value of the polygon vertices for a given axis.

Parameters:
axis - The axis id (X_AXIS, Y_AXIS, Z_AXIS).
Returns:
Returns the minimum value of the polygon vertices.

getMaxValue

public double getMaxValue(int axis)
Returns the maximum value of the polygon vertices for a given axis.

Parameters:
axis - The axis id (X_AXIS, Y_AXIS, Z_AXIS).
Returns:
Returns the maximum value of the polygon vertices.

isClosedPolygon

public boolean isClosedPolygon()
Returns true if the polyon is a closed, rather than just a polyline.

Returns:
Returns true if the polyon is a closed, rather than just a polyline.

draw

public void draw(java.awt.Graphics2D g2)
The draw function for the class.

Parameters:
g2 - A graphics context

draw

public static void draw(java.awt.Graphics2D g2,
                        Polygon3D polygon)
A static routine that draws a Polygon3D object.

Parameters:
g2 - A graphics context
polygon - The source polygon.

getCoordinateSystem

public PhysicalCoordinates getCoordinateSystem()
Get the objects coordinate system.

Returns:
Return the objects coordinate system.

setCoordinateSystem

public void setCoordinateSystem(PhysicalCoordinates value)
Set the objects coordinate system.

Parameters:
value - Set the objects coordinate system.

getInsideAttribute

public ChartAttribute getInsideAttribute()
Get inside color attribute of the object.

Returns:
Returns the objects inside attribute.

setInsideAttribute

public void setInsideAttribute(ChartAttribute value)
Set inside color attribute of the object.

Parameters:
value - Set the objects inside attribute.

getOutsideAttribute

public ChartAttribute getOutsideAttribute()
Get outside color attribute of the object.

Returns:
Returns the objects outside attribute.

setOutsideAttribute

public void setOutsideAttribute(ChartAttribute value)
Set outside color attribute of the object.

Parameters:
value - Set the objects outside attribute.

getGroupIndex

public int getGroupIndex()
Get the group index of the polygon.

Returns:
Returns the group index of the polygon.

setGroupIndex

public void setGroupIndex(int value)
Set the group index of the polygon.

Parameters:
value - Set the group index of the polygon.

getDataPointIndex

public int getDataPointIndex()
Get data point index of the polygon.

Returns:
Returns the data point index of the polygon.

setDataPointIndex

public void setDataPointIndex(int value)
Set data point index of the polygon.

Parameters:
value - Set the data point index of the polygon.

getEnableCullRearFacing

public boolean getEnableCullRearFacing()
Returns true if culling of rear facing polygons is enabled.

Returns:
Returns true if culling of rear facing polygons is enabled.

setEnableCullRearFacing

public void setEnableCullRearFacing(boolean value)
Set to true to enable the culling of rear facing polygons.

Parameters:
value - Set to true to enable the culling of rear facing polygons.

getEnablePolygon

public boolean getEnablePolygon()
Returns true to enable the polygon.

Returns:
Returns true to enable the polygon.

setEnablePolygon

public void setEnablePolygon(boolean value)
Set to true to enable the polygon.

Parameters:
value - Set to true to enable the polygon.

getCoordinateType

public int getCoordinateType()
Get the coordinate system type of the polygon (SCREEN_POS, DEV_POS, PHYS_POS).

Returns:
Returns the coordinate system type of the polygon.

setCoordinateType

public void setCoordinateType(int value)
Set the coordinate system type of the polygon (SCREEN_POS, DEV_POS, PHYS_POS).

Parameters:
value - Set the coordinate system type of the polygon.

count

public int count()
Get the number of vertices.

Returns:
Returns the the number of vertices.

getPointArray

public Point3DArray getPointArray()
Get the pointArray object holding the point list that define the polygon.

Returns:
he pointArray object holding the point list that define the polygon.

getElement

public ChartPoint3D getElement(int index)
This accessor is the indexer for the class and get/sets the value of an individual vertex in the polygon.

Parameters:
index - Get the point at the index element.
Returns:
Returns the ChartPoint3D element at index.

setElement

public void setElement(int index,
                       ChartPoint3D value)
This accessor is the indexer for the class and get/sets the value of an individual vertex in the polygon.

Parameters:
index - Set the point at the index element.
value - Set the point at the index element using this value.