edu.umd.cs.jazz.util
Class ZUtil

java.lang.Object
  |
  +--edu.umd.cs.jazz.util.ZUtil
All Implemented Interfaces:
java.io.Serializable

public class ZUtil
extends java.lang.Object
implements java.io.Serializable

ZUtil provides some generic, useful routines.

Warning: Serialized and ZSerialized objects of this class will not be compatible with future Jazz releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Jazz. A future release of Jazz will provide support for long term persistence.

Author:
Ben Bederson
See Also:
Serialized Form

Constructor Summary
ZUtil()
           
 
Method Summary
static double angleBetweenPoints(double x, double y, double ax, double ay, double bx, double by)
          Returns the angle in radians between point a and point b from point pt, that is the angle between a-pt-b.
static double angleBetweenPoints(java.awt.geom.Point2D pt, java.awt.geom.Point2D a, java.awt.geom.Point2D b)
          Returns the angle in radians between point a and point b from point pt, that is the angle between a-pt-b.
static java.awt.image.BufferedImage createThumbnailImage(ZNode node, java.awt.Dimension thumbnailSize)
          Returns a BufferedImage of thumbnailSize with the node rendered into the image.
static boolean intersectsPolygon(java.awt.geom.Rectangle2D rect, double[] xp, double[] yp)
          Determines if any part of the rectangle is inside this polygon.
static double inverseTransformDimension(java.awt.geom.Dimension2D aDimension, java.awt.geom.AffineTransform aTransform)
          Modify the dimension paramater by applying the inverse of the given transform.
static double inverseTransformRectangle(java.awt.geom.Rectangle2D aRectangle, java.awt.geom.AffineTransform aTransform)
          Modify the aRectangle paramater by applying the inverse of the given transform.
static boolean isInsidePolygon(double x, double y, int np, double[] xp, double[] yp)
          Determines if the point is inside the polygon.
static boolean isInsidePolygon(java.awt.geom.Rectangle2D rect, int np, double[] xp, double[] yp)
          Determines if a rectangle is inside a polygon.
static boolean rectIntersectsLine(java.awt.geom.Rectangle2D rect, double x1, double y1, double x2, double y2)
          Tests if the specified line segment intersects the interior of the specified Rectangle2D.
static boolean rectIntersectsPolyline(java.awt.geom.Rectangle2D rect, double[] xp, double[] yp, double penWidth)
          Determine if the specified rectangle intersects the specified polyline.
static double transformDimension(java.awt.geom.Dimension2D aDimension, java.awt.geom.AffineTransform aTransform)
          Modify the dimension paramater by applying the the given transform.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZUtil

public ZUtil()
Method Detail

createThumbnailImage

public static java.awt.image.BufferedImage createThumbnailImage(ZNode node,
                                                                java.awt.Dimension thumbnailSize)
Returns a BufferedImage of thumbnailSize with the node rendered into the image. The node is scaled to fit within the image without changing its aspect ratio.

NOTE: ZSceneGraphObjects that access the ZDrawingSurface or ZCamera in their render method without checking for null values will throw exceptions when passed to this method.

Contributed by Philippe Converset.

Parameters:
node - The node to render.
thumbnailSize - The size of the resulting BufferedImage.
Returns:
BufferedImage The image with the node rendered into it.

rectIntersectsLine

public static boolean rectIntersectsLine(java.awt.geom.Rectangle2D rect,
                                         double x1,
                                         double y1,
                                         double x2,
                                         double y2)
Tests if the specified line segment intersects the interior of the specified Rectangle2D.

Returns:
true if the specified line segment intersects the interior of this Rectangle2D; false otherwise.

rectIntersectsPolyline

public static boolean rectIntersectsPolyline(java.awt.geom.Rectangle2D rect,
                                             double[] xp,
                                             double[] yp,
                                             double penWidth)
Determine if the specified rectangle intersects the specified polyline.

Parameters:
rect - The rectangle that is being tested for intersection
xp - The array of X-coordinates that determines the polyline
yp - The array of Y-coordinates that determines the polyline
penWidth - The width of the polyline
Returns:
true if the rectangle intersects the polyline.

angleBetweenPoints

public static double angleBetweenPoints(java.awt.geom.Point2D pt,
                                        java.awt.geom.Point2D a,
                                        java.awt.geom.Point2D b)
Returns the angle in radians between point a and point b from point pt, that is the angle between a-pt-b.

Returns:
the angle

angleBetweenPoints

public static double angleBetweenPoints(double x,
                                        double y,
                                        double ax,
                                        double ay,
                                        double bx,
                                        double by)
Returns the angle in radians between point a and point b from point pt, that is the angle between a-pt-b.

Returns:
the angle

intersectsPolygon

public static boolean intersectsPolygon(java.awt.geom.Rectangle2D rect,
                                        double[] xp,
                                        double[] yp)
Determines if any part of the rectangle is inside this polygon.

Parameters:
rect - The rectangle being tested for intersecting this polygon
Returns:
true if the rectangle intersects the polygon

isInsidePolygon

public static boolean isInsidePolygon(double x,
                                      double y,
                                      int np,
                                      double[] xp,
                                      double[] yp)
Determines if the point is inside the polygon.

Returns:
true if the point is inside the polygon

isInsidePolygon

public static boolean isInsidePolygon(java.awt.geom.Rectangle2D rect,
                                      int np,
                                      double[] xp,
                                      double[] yp)
Determines if a rectangle is inside a polygon. Warning: this code only works for simple convex polygons.

Parameters:
rect - The rectangle being tested for containment within a polygon
Returns:
true if the rectangle is inside the polygon

transformDimension

public static double transformDimension(java.awt.geom.Dimension2D aDimension,
                                        java.awt.geom.AffineTransform aTransform)
Modify the dimension paramater by applying the the given transform.

Parameters:
aDimension - the dimension to which the transform will be applied.
aTransform - the transform that will be applied to the dimension.
Returns:
dz The change in scale from applying aTransform.

inverseTransformDimension

public static double inverseTransformDimension(java.awt.geom.Dimension2D aDimension,
                                               java.awt.geom.AffineTransform aTransform)
                                        throws java.awt.geom.NoninvertibleTransformException
Modify the dimension paramater by applying the inverse of the given transform.

Parameters:
aDimension - the dimension to which the inverse transform will be applied.
aTransform - the transform who's inverse will be applied to the dimension.
Returns:
dz The change in scale from applying aTransform.
java.awt.geom.NoninvertibleTransformException

inverseTransformRectangle

public static double inverseTransformRectangle(java.awt.geom.Rectangle2D aRectangle,
                                               java.awt.geom.AffineTransform aTransform)
                                        throws java.awt.geom.NoninvertibleTransformException
Modify the aRectangle paramater by applying the inverse of the given transform. This method works without creating a new transform object so it should be more efficient then calling aTransform.createInverseTransform() and applying that result to the rectangle.

Parameters:
aRectangle - the rectangle to which the inverse transform will be applied.
aTransform - the transform who's inverse will be applied to the size.
Returns:
dz The change in scale from applying aTransform.
java.awt.geom.NoninvertibleTransformException


Copyright 2003 by University of Maryland, College Park, MD 20742, USA All rights reserved.