j3d.org Code

org.j3d.geom
Class TorusGenerator

java.lang.Object
  extended by org.j3d.geom.GeometryGenerator
      extended by org.j3d.geom.TorusGenerator

public class TorusGenerator
extends GeometryGenerator

A generator of Torus geometry values.

The outer radius is the radius of the center of the tube that forms the torus.The torus has the outer radius in the X-Z plane and it increments along the positive Y axis. The loop starts at the origin on the positive X axis and rotates counter-clockwise when looking down the -Y axis towards the X-Z plane.

TODO
Look at trig optimisation techniques such as creating lookup tables.

Version:
$Revision: 1.3 $
Author:
Justin Couch

Constructor Summary
TorusGenerator()
          Construct a default torus.
TorusGenerator(float ir, float or)
          Construct a torus with the given inner and outer radius values.
TorusGenerator(float ir, float or, int ifc, int ofc)
          Construct a torus with given radius values and number of facets.
TorusGenerator(int ifc, int ofc)
          Construct a default torus with a selectable number of facets.
 
Method Summary
 void generate(GeometryData data)
          Generate a new set of geometry items shaped on the passed data.
 float[] getDimensions()
          Get the dimensions of the cylinder.
 int getVertexCount(GeometryData data)
          Get the number of vertices that this generator will create for the shape given in the definition.
 void setDimensions(float ir, float or)
          Change the dimensions of the torus to be generated.
 void setFacetCount(int ifc, int ofc)
          Change the number of facets used to create this cone.
 
Methods inherited from class org.j3d.geom.GeometryGenerator
createFaceNormal, createFaceNormal, createRadialNormal, createRadialNormal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TorusGenerator

public TorusGenerator()
Construct a default torus. The inner radius is 0.5, outer radius 2.0 and there are 16 facets in each direction for the inner and outer radius.


TorusGenerator

public TorusGenerator(float ir,
                      float or)
Construct a torus with the given inner and outer radius values. There are 16 facets in each direction for the inner and outer radius.

Parameters:
ir - The inner radius to use
or - The outer radius to use

TorusGenerator

public TorusGenerator(int ifc,
                      int ofc)
Construct a default torus with a selectable number of facets. The inner radius is 0.5 and the outer radius is 2.0. The minimum number of facets is 3.

Parameters:
ifc - The number of facets to use around the inner radius
ofc - The number of facets to use around the outer radius
Throws:
java.lang.IllegalArgumentException - The number of facets is less than 3

TorusGenerator

public TorusGenerator(float ir,
                      float or,
                      int ifc,
                      int ofc)
Construct a torus with given radius values and number of facets. The minimum number of facets is 3.

Parameters:
ir - The inner radius to use
or - The outer radius to use
ifc - The number of facets to use around the inner radius
ofc - The number of facets to use around the outer radius
Throws:
java.lang.IllegalArgumentException - The number of facets is less than 4
Method Detail

getDimensions

public float[] getDimensions()
Get the dimensions of the cylinder. These are returned as 2 values of inner and outer radius respectively for the array. A new array is created each time so you can do what you like with it.

Returns:
The current size of the cone

setDimensions

public void setDimensions(float ir,
                          float or)
Change the dimensions of the torus to be generated. Calling this will make the points be re-calculated next time you ask for geometry or normals.

Parameters:
ir - The ir of the cone to generate
or - The or of the bottom of the cone

setFacetCount

public void setFacetCount(int ifc,
                          int ofc)
Change the number of facets used to create this cone. This will cause the geometry to be regenerated next time they are asked for. The minimum number of facets is 4.

Parameters:
ifc - The number of facets to use around the inner radius
ofc - The number of facets to use around the outer radius
Throws:
java.lang.IllegalArgumentException - The number of facets is less than 4

getVertexCount

public int getVertexCount(GeometryData data)
                   throws UnsupportedTypeException
Get the number of vertices that this generator will create for the shape given in the definition.

Specified by:
getVertexCount in class GeometryGenerator
Parameters:
data - The data to shape the calculations on
Returns:
The vertex count for the object
Throws:
UnsupportedTypeException - The generator cannot handle the type of geometry you have requested.

generate

public void generate(GeometryData data)
              throws UnsupportedTypeException,
                     InvalidArraySizeException
Generate a new set of geometry items shaped on the passed data. If the data does not contain the right minimum array lengths an exception will be generated. If the array reference is null, this will create arrays of the correct length and assign them to the return value.

Specified by:
generate in class GeometryGenerator
Parameters:
data - The data to shape the calculations on
Throws:
InvalidArraySizeException - The array is not big enough to contain the requested geometry
UnsupportedTypeException - The generator cannot handle the type of geometry you have requested

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org