JavaView® v2.12

jv.geom
Class PgPolygon

java.lang.Object
  |
  +--jv.object.PsObject
        |
        +--jv.project.PgGeometry
              |
              +--jv.geom.PgPointSet
                    |
                    +--jv.geom.PgPolygon
All Implemented Interfaces:
java.lang.Cloneable, PgGeometryIf, PsUpdateIf, java.io.Serializable
Direct Known Subclasses:
PgBezierCurve, PgBndPolygon

public class PgPolygon
extends PgPointSet

Base class for polygons given as consequtive list of polygon vertices. The class interprets the vertices in the vertex array of its superclass PgPointSet as consequtive points of a polygon. Therefore, this class mainly consists of polygon properties, for example, polygon color, additional to the geometric information contained in its superclass.

The dimension of all points is determined as argument of the constructor and cannot be changed later. See PgPointSet for details about allocation and access.

A good starting to obtain further insight are methods like computeEight(int) (if source code access to JavaView is available), or the tutorial applets of JavaView.

Version:
07.07.00, 2.50 revised (kp) Edge methods added and jvx exchange.
02.04.00, 2.00 revised (kp) PdColor replaced with Color in lists.
00.00.98, 1.00 created (kp)
Author:
Konrad Polthier
See Also:
PgPointSet, Serialized Form

Field Summary
 int BINORMAL
           
 int CURVATURE_NORMAL
           
 int NORMAL
           
 int OFFSET_NORMAL
           
 
Fields inherited from class jv.object.PsObject
HAS_CONFIG_PANEL, HAS_INFO_PANEL, HAS_MATERIAL_PANEL, HAS_TEXTURE_PANEL, INSPECTOR_INFO, INSPECTOR_INFO_EXT, IS_DELETED, IS_FIXED, IS_SELECTED, IS_USED, NUM_TAGS
 
Fields inherited from interface jv.project.PgGeometryIf
AMBIENT_H2_HYPERBOLIC, AMBIENT_H3_HYPERBOLIC, AMBIENT_H4_HYPERBOLIC, AMBIENT_PROJECTIONS, AMBIENT_R1_EUCLIDEAN, AMBIENT_R2_EUCLIDEAN, AMBIENT_R3_EUCLIDEAN, AMBIENT_R4_EUCLIDEAN, AMBIENT_R5_EUCLIDEAN, AMBIENT_S1_SPHERE, AMBIENT_S2_SPHERE, AMBIENT_S3_SPHERE, AMBIENT_S4_SPHERE, AMBIENT_SPACES, INSPECTOR_CONTROL, INSPECTOR_CONTROL_EXT, INSPECTOR_MATERIAL, INSPECTOR_MATERIAL_EXT, INSPECTOR_TEXTURE, INSPECTOR_TEXTURE_EXT, LABEL_BASE, LABEL_CENTER, LABEL_HEAD, LABEL_MIDDLE, LABEL_TAIL, LABEL_TOP, METHOD_EXT, PROJ_KLEIN_BALL, PROJ_PARALLEL, PROJ_POINCARE_BALL, PROJ_STEREOGRAPHIC, PROJ_UPPER_HALFSPACE
 
Constructor Summary
PgPolygon()
          Constructor of a polygon in three-dimensional space.
PgPolygon(int aVertexDim)
          Constructor of a polygon set in a space of given dimension.
 
Method Summary
 boolean blend(double s, PgPolygon a, double t, PgPolygon b)
          Blend between two Polygons using this = s*a + t*b
 boolean checkTriangleCut(int vertexInd, PdVector normal)
          Given a simple closed, nearly planar polygon, then the function tests whether three successive points of the polygon form a triangle which can be cut off the polygon, i.e. the triangle does not contain any other vertex of the polygon.
 java.lang.Object clone()
          Duplicate geometry by recursively cloning all instance variables except inspector panels and lists of registered listeners.
 void computeCircle(int numPoints, double radius)
          Compute circle centered at origin in xy-plane with given radius including vertex normals.
 void computeEight(int numPoints)
          Compute figure eight in xy-plane with given radius including vertex normals.
 void copy(PgGeometry aGeom)
          Copy instance variables by duplication, not by copying a reference.
 java.awt.Color getGlobalPolygonColor()
          Get global polygon color which is used if no local colors are available.
 double getGlobalPolygonSize()
          Get thickness in pixels of polygon when drawn in display.
 java.awt.Color getGlobalPolygonTagColor()
          Get global color of tagged polygons.
 PgJvxSrc getJvx()
          Fills a geometry object with data from this instance, for example, to print to file.
 double getLength()
          Compute geometric length of polygon as the sum of all edge lengths.
 PiVector getPolygon()
          Get indices of polygon as index vector.
 void init()
          Initialize and reset instance variables after call to super.init().
 PvPickEvent intersectionWithLine(PdVector rayBase, PdVector rayDir)
          Find intersection of polygon with a given ray.
 boolean isClosed()
          Check whether polygon is closed, i.e.if endpoints are connected by additional edge.
 boolean isShowingEdgeColors()
          Determine whether drawing of edge colorsis enabled.
 boolean isShowingEdgeLabels()
          Determine whether showing of edge labels is enabled.
 boolean isShowingEdgeNormals()
          Determine whether drawing of edge normalsis enabled.
 boolean isShowingEdges()
          Determine whether drawing of edges of polygonis enabled.
 boolean isShowingPolygonColors()
          Set flag to enable drawing of polygon colors.
 boolean isShowingPolygonEndArrow()
          Determine whether drawing of arrow at last point of polygon is enabled.
 boolean isShowingPolygonStartArrow()
          Determine whether drawing of arrow at first point of polygon is enabled.
 void makeBiNormals()
          Compute binormals at vertices which are orthogonal to both adjacent edges.
 void makeCurvatureNormals()
          Compute normals at vertices as edge bisectors with length equal to (Pi-vertexAngle).
 void makeNormals()
          Compute normals at vertices as edge bisectors with unit length.
 void makeNormals(int type, double length)
          Compute normals at vertices which lie in the span of the adjacent edges.
 void makeOffsetNormals()
          Compute normals at vertices as edge bisectors whose tip lies on an offset==1 curve.
 void paint(PvGeometryIf dc)
          Major rendering method fills an internal container class supplied by the display.
 void setClosed(boolean flag)
          Set flag that polygon is closed.
 void setGlobalPolygonColor(java.awt.Color color)
          Set global polygon color to be used if no local colors are available.
 void setGlobalPolygonSize(double size)
          Set thickness in pixels of polygon when drawn in display.
 void setGlobalPolygonTagColor(java.awt.Color color)
          Set global color of tagged polygons.
 void setJvx(PgJvxSrc src)
          Fill this instance with data from a geometry source, for example, previously read from file.
 void showEdgeColors(boolean flag)
          Set flag to enable drawing of edge colors.
 void showEdgeLabels(boolean flag)
          Set flag to enable drawing of edge labels in display.
 void showEdgeNormals(boolean flag)
          Set flag to enable drawing of edge normals.
 void showEdges(boolean flag)
          Set flag to enable drawing of edges of polygon.
 void showPolygonColors(boolean flag)
          Set flag to enable drawing of polygon colors.
 void showPolygonEndArrow(boolean flag)
          Set flag to enable drawing of arrow at last point of polygons.
 void showPolygonStartArrow(boolean flag)
          Set flag to enable drawing of arrow at first point of polygons.
 java.lang.String toString()
          Create a multi-line string representation with detailed information about all instance variables.
 PiVector[] triangulate()
          Given a simple closed, nearly planar polygon, then the method triangulates the patch by successively removing the vertex with the smallest interior angle.
 boolean update(java.lang.Object event)
          Update the class whenever a child has changed.
 void useGlobalPolygonColor(boolean flag)
          Deprecated. use showPolygonColors(boolean)
 void useGlobalPolygonSize(boolean flag)
          Use global polygon size instead of sizing each edge individually.
 
Methods inherited from class jv.geom.PgPointSet
addVectorField, addVertex, assureVertexColors, assureVertexNormals, assureVertexTextures, blend, clearTagVertex, computeCylinder, computeDisk, computePlane, computeRotation, computeSnail, computeSphere, computeTorus, flipOrientation, getAmbientBounds, getBounds, getCenterOfBndBox, getCenterOfGravity, getDimOfColors, getDimOfTextures, getDimOfVectors, getGlobalVectorColor, getGlobalVectorLength, getGlobalVectorSize, getGlobalVertexColor, getGlobalVertexNormalColor, getGlobalVertexNormalLength, getGlobalVertexNormalSize, getGlobalVertexSize, getGlobalVertexTagColor, getIndexOfVectorField, getMaxNumVertices, getNumVectorFields, getNumVertices, getTexture, getTextureImage, getTextureImageName, getVectorField, getVectorField, getVertex, getVertexColor, getVertexColors, getVertexNormal, getVertexNormals, getVertexTextures, getVertices, hasTagVertex, hasVertex, hasVertex, hasVertexColors, hasVertexNormals, hasVertexTextures, isDefaultLabelEnabled, isShowingIndices, isShowingTaggedVertices, isShowingVectorArrow, isShowingVectorArrows, isShowingVectorColors, isShowingVectorField, isShowingVertexColors, isShowingVertexLabels, isShowingVertexNormalArrow, isShowingVertexNormals, isShowingVertexTexture, isShowingVertices, makeColorFromVectorLength, makeVertexColorsFromXYZ, makeVertexColorsFromZ, makeVertexColorsFromZHue, makeVertexNormals, makeVertexTextureFromBndBox, makeVertexTextureFromCylinder, makeVertexTextureFromSphere, merge, projectToSphere, reflect, removeAllVectorFields, removeMarkedVertices, removeVectorField, removeVertex, scale, scale, setCenterOfBndBox, setDefaultLabelEnabled, setDimOfColors, setDimOfTextures, setDimOfVectors, setGlobalVectorColor, setGlobalVectorLength, setGlobalVectorSize, setGlobalVertexColor, setGlobalVertexNormalColor, setGlobalVertexNormalLength, setGlobalVertexNormalSize, setGlobalVertexSize, setGlobalVertexTagColor, setNumVertices, setState, setTagVertex, setTexture, setTextureImage, setTextureImageName, setTransparency, setVertex, setVertex, setVertex, setVertex, setVertexColor, setVertexColors, setVertexNormal, setVertexNormals, setVertexTextures, setVertices, showIndices, showTaggedVertices, showVectorArrow, showVectorArrows, showVectorColors, showVectorField, showVectorFields, showVertexColors, showVertexLabels, showVertexNormalArrow, showVertexNormals, showVertexTexture, showVertices, translate
 
Methods inherited from class jv.project.PgGeometry
addDisplay, addElement, addPolygon, clearTagElement, clearTagPolygon, fillMethodMenu, getAmbientInvMatrix, getAmbientMatrix, getAmbientProjection, getAmbientSpace, getAuthorInfo, getAuthors, getCenter, getCenterOfElement, getControlPanel, getDiameter, getDimOfSimplex, getDimOfVertices, getDisplays, getElement, getGeometryInfo, getLabelAttribute, getMaterialPanel, getModelMatrix, getPolygon, getTitle, getVersion, getVersionType, hasAmbientMatrix, hasDisplay, hasModelMatrix, hasTagElement, hasTagPolygon, isConfigurable, isShowingBndBox, isShowingCenter, isShowingTitle, isVisible, removeDisplay, removeElement, removePolygon, setAmbientMatrix, setAmbientProjection, setAmbientSpace, setAuthorInfo, setAuthors, setCenter, setDimOfSimplex, setElement, setGeometryInfo, setLabelAttribute, setLabelAttribute, setModelMatrix, setPolygon, setTagElement, setTagPolygon, setTitle, setVersion, setVersionType, setVisible, showBndBox, showCenter, showTitle
 
Methods inherited from class jv.object.PsObject
addInspector, addUpdateListener, assureInspector, clearTag, clone, clone, copy, getFather, getInfoPanel, getInspector, getName, getNumObjects, hasInspector, hasTag, hasUpdateListener, instanceOf, instanceOf, removeInspector, removeUpdateListener, setName, setParent, setTag, updatePanels
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jv.project.PgGeometryIf
assureInspector, getInfoPanel, getName, setName
 
Methods inherited from interface jv.object.PsUpdateIf
getFather, setParent
 

Field Detail

NORMAL

public int NORMAL

BINORMAL

public int BINORMAL

OFFSET_NORMAL

public int OFFSET_NORMAL

CURVATURE_NORMAL

public int CURVATURE_NORMAL
Constructor Detail

PgPolygon

public PgPolygon()
Constructor of a polygon in three-dimensional space.

PgPolygon

public PgPolygon(int aVertexDim)
Constructor of a polygon set in a space of given dimension.
Method Detail

init

public void init()
Initialize and reset instance variables after call to super.init().
Overrides:
init in class PgPointSet

getJvx

public PgJvxSrc getJvx()
Fills a geometry object with data from this instance, for example, to print to file.
Overrides:
getJvx in class PgPointSet
Returns:
src a geometry source to be filled with data from this instance.

setJvx

public void setJvx(PgJvxSrc src)
Fill this instance with data from a geometry source, for example, previously read from file.
Overrides:
setJvx in class PgPointSet
Parameters:
src - a geometry source used to fill this instance with data.

clone

public java.lang.Object clone()
Duplicate geometry by recursively cloning all instance variables except inspector panels and lists of registered listeners. The parent relationship is maintained only within this class but not to external classes. In general, all links of the clone to external objects are set to null. Tags of this object are not copied but maybe copied of subclasses.
Overrides:
clone in class PgPointSet
See Also:
#copy(PgPolygon)

copy

public void copy(PgGeometry aGeom)
Copy instance variables by duplication, not by copying a reference.
Overrides:
copy in class PgPointSet

toString

public java.lang.String toString()
Create a multi-line string representation with detailed information about all instance variables.
Overrides:
toString in class PgPointSet

getGlobalPolygonColor

public java.awt.Color getGlobalPolygonColor()
Get global polygon color which is used if no local colors are available.

getGlobalPolygonTagColor

public java.awt.Color getGlobalPolygonTagColor()
Get global color of tagged polygons.

getGlobalPolygonSize

public double getGlobalPolygonSize()
Get thickness in pixels of polygon when drawn in display.

setGlobalPolygonColor

public void setGlobalPolygonColor(java.awt.Color color)
Set global polygon color to be used if no local colors are available.

setGlobalPolygonTagColor

public void setGlobalPolygonTagColor(java.awt.Color color)
Set global color of tagged polygons.

setGlobalPolygonSize

public void setGlobalPolygonSize(double size)
Set thickness in pixels of polygon when drawn in display.

showPolygonColors

public void showPolygonColors(boolean flag)
Set flag to enable drawing of polygon colors.

useGlobalPolygonColor

public void useGlobalPolygonColor(boolean flag)
Deprecated. use showPolygonColors(boolean)

Set flag of using global polygon color instead of coloring each polygon individually.

useGlobalPolygonSize

public void useGlobalPolygonSize(boolean flag)
Use global polygon size instead of sizing each edge individually.

isShowingEdgeLabels

public boolean isShowingEdgeLabels()
Determine whether showing of edge labels is enabled.

isShowingEdges

public boolean isShowingEdges()
Determine whether drawing of edges of polygonis enabled.

isShowingEdgeNormals

public boolean isShowingEdgeNormals()
Determine whether drawing of edge normalsis enabled.

isShowingEdgeColors

public boolean isShowingEdgeColors()
Determine whether drawing of edge colorsis enabled.

isShowingPolygonStartArrow

public boolean isShowingPolygonStartArrow()
Determine whether drawing of arrow at first point of polygon is enabled.

isShowingPolygonEndArrow

public boolean isShowingPolygonEndArrow()
Determine whether drawing of arrow at last point of polygon is enabled.

isShowingPolygonColors

public boolean isShowingPolygonColors()
Set flag to enable drawing of polygon colors.

showEdgeLabels

public void showEdgeLabels(boolean flag)
Set flag to enable drawing of edge labels in display.

showEdges

public void showEdges(boolean flag)
Set flag to enable drawing of edges of polygon.

showEdgeNormals

public void showEdgeNormals(boolean flag)
Set flag to enable drawing of edge normals.

showEdgeColors

public void showEdgeColors(boolean flag)
Set flag to enable drawing of edge colors.

showPolygonStartArrow

public void showPolygonStartArrow(boolean flag)
Set flag to enable drawing of arrow at first point of polygons.

showPolygonEndArrow

public void showPolygonEndArrow(boolean flag)
Set flag to enable drawing of arrow at last point of polygons.

update

public boolean update(java.lang.Object event)
Update the class whenever a child has changed. Method is usually invoked from the children.
Overrides:
update in class PgPointSet
Following copied from interface: jv.object.PsUpdateIf
Parameters:
event - carries a lot of information
Returns:
true if event has been handled, otherwise false
See Also:
PsObject, PsUpdateIf.getFather(), PsUpdateIf.setParent(PsUpdateIf)

paint

public void paint(PvGeometryIf dc)
Major rendering method fills an internal container class supplied by the display. See jv.project.PgGeometryIf for detailed information.
Overrides:
paint in class PgPointSet
See Also:
PgGeometryIf

getPolygon

public PiVector getPolygon()
Get indices of polygon as index vector.

getLength

public double getLength()
Compute geometric length of polygon as the sum of all edge lengths. If polygon is closed then the distance of the first and last vertex is added to the polygon length.
Returns:
length of polygon
See Also:
isClosed()

isClosed

public boolean isClosed()
Check whether polygon is closed, i.e.if endpoints are connected by additional edge.
Returns:
flag whether polygon is closed.
See Also:
setClosed(boolean)

setClosed

public void setClosed(boolean flag)
Set flag that polygon is closed. In the previous version 1.00 an additional vertex might have been allocated. This version just sets a flag.
Parameters:
flag - true closes polygons
See Also:
isClosed()

computeEight

public void computeEight(int numPoints)
Compute figure eight in xy-plane with given radius including vertex normals.
Parameters:
numPoints - Discretization of polygon

computeCircle

public void computeCircle(int numPoints,
                          double radius)
Compute circle centered at origin in xy-plane with given radius including vertex normals.
Parameters:
numPoints - Discretization of polygon
radius - Radius of circle

blend

public boolean blend(double s,
                     PgPolygon a,
                     double t,
                     PgPolygon b)
Blend between two Polygons using this = s*a + t*b
Parameters:
s, - t weights of vertices of each Polygon
a, - b two Polygons used for blending

makeNormals

public void makeNormals()
Compute normals at vertices as edge bisectors with unit length. All normals are oriented to show to the same side of the polygon as the first normal which is non-degenerate.

This method correctly handles polygons with sequences of parallel edges and multiple vertices.


makeBiNormals

public void makeBiNormals()
Compute binormals at vertices which are orthogonal to both adjacent edges. All binormals lie in the span of the two edges of a vertex and all binormals have the same orientation as the normal vector of the enclosed patch surface.

This method correctly handles polygons with sequences of parallel edges and multiple vertices.


makeOffsetNormals

public void makeOffsetNormals()
Compute normals at vertices as edge bisectors whose tip lies on an offset==1 curve. All normals are oriented to show to the same side of the polygon as the first normal which is non-degenerate.

This method correctly handles polygons with sequences of parallel edges and multiple vertices.


makeCurvatureNormals

public void makeCurvatureNormals()
Compute normals at vertices as edge bisectors with length equal to (Pi-vertexAngle). All normals are oriented to show to the same side of the polygon as the first normal which is non-degenerate.

This method correctly handles polygons with sequences of parallel edges and multiple vertices.


makeNormals

public void makeNormals(int type,
                        double length)
Compute normals at vertices which lie in the span of the adjacent edges. All normals are oriented to show to the same side of the polygon as the first normal which is non-degenerate.

This method correctly handles polygons with sequences of parallel edges and multiple vertices.


checkTriangleCut

public boolean checkTriangleCut(int vertexInd,
                                PdVector normal)
Given a simple closed, nearly planar polygon, then the function tests whether three successive points of the polygon form a triangle which can be cut off the polygon, i.e. the triangle does not contain any other vertex of the polygon.

Remark: this condition is only valid of the projection of the polygon onto a plane orthogonal to the normal of the polygon is a simple closed curve with no self-intersections.

Fuer den Test wird abgefragt, ob die uebrigen Eckpunkte des Polygons im Innern des vom Dreieck p1,p2,p3 und der Normalen orient gebildeten Prismas liegt. Wenn alle Punkte ausserhalb liegen, so verlaeuft Linie im Innern d. Polygons.

Parameters:
vertexInd - index of middle vertex which might be cut off
normal - normal of polygon, used as orientation, i.e. polygon runs counter-clockwise around normal

triangulate

public PiVector[] triangulate()
Given a simple closed, nearly planar polygon, then the method triangulates the patch by successively removing the vertex with the smallest interior angle. The method can handle non-convex polygons.

ToDo: But until now it cannot handle situations where an edge introduced by removing a vertex may intersect the polygon somewhere else. To solve this problem the above method checkTriangleCut must be employed.

Returns:
Array of vectors each containing the vertex indices of a triangle.

intersectionWithLine

public PvPickEvent intersectionWithLine(PdVector rayBase,
                                        PdVector rayDir)
Find intersection of polygon with a given ray. Closest polygon edge is located. Method is used for interactive picking.
Overrides:
intersectionWithLine in class PgPointSet
Parameters:
rayBase - base point of ray eventually hitting the polygon set
rayDir - direction point of ray eventually hitting the polygon set
Returns:
full information about hit polygon, barycentric coordinates etc.

JavaView® v2.12

The software JavaView® is copyright protected. All Rights Reserved.