j3d.org Code

org.j3d.geom
Class SpringGenerator

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

public class SpringGenerator
extends GeometryGenerator

A generator of Spring geometry with customisable inner radius, outer radius, number of loops, spacing and facet count.

The outer radius is the radius of the center of the tube that forms the spring. The spring has the outer radius in the X-Z plane and it increments along the positive Y axis. The first 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.

Version:
$Revision: 1.6 $
Author:
Justin Couch

Constructor Summary
SpringGenerator()
          Construct a default spring that has:
inner radius: 0.25
outer radius: 1.0
inner facet count: 16
outer facet count: 16
loop count: 4
loop spacing: 1.0
SpringGenerator(float spacing)
          Construct a spring with the given loop spacing and all other values fixed at the defaults.
SpringGenerator(float ir, float or)
          Construct a spring that has the given radius values with all other values fixed at the defaults
SpringGenerator(float ir, float or, float spacing, int lc)
          Construct a spring with the given radius, spacing and loop count information.
SpringGenerator(float ir, float or, float spacing, int lc, int ifc, int ofc)
          Construct a spring with the given radius, spacing and loop count information, and facet count.
SpringGenerator(int lc)
          Construct a spring that has the given number of loops with all other values fixed at the defaults.
SpringGenerator(int ifc, int ofc)
          Construct a spring that has the selected number of facets but with all other values fixed at the defaults.
 
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 spring.
 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 spring.
 void setLoopDimensions(float spacing, int lc)
          Change the loop information.
 
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

SpringGenerator

public SpringGenerator()
Construct a default spring that has:
inner radius: 0.25
outer radius: 1.0
inner facet count: 16
outer facet count: 16
loop count: 4
loop spacing: 1.0


SpringGenerator

public SpringGenerator(float ir,
                       float or)
Construct a spring that has the given radius values with all other values fixed at the defaults

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

SpringGenerator

public SpringGenerator(int lc)
Construct a spring that has the given number of loops with all other values fixed at the defaults. The loop count must be one or more.

Parameters:
lc - The loop count
Throws:
java.lang.IllegalArgumentException - The loop count was invalid

SpringGenerator

public SpringGenerator(float spacing)
Construct a spring with the given loop spacing and all other values fixed at the defaults.

Parameters:
spacing - The spacing between loops

SpringGenerator

public SpringGenerator(int ifc,
                       int ofc)
Construct a spring that has the selected number of facets but with all other values fixed at the defaults. 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

SpringGenerator

public SpringGenerator(float ir,
                       float or,
                       float spacing,
                       int lc)
Construct a spring with the given radius, spacing and loop count information. All other values are defaults. The loop count must be greater than or equal to 1.

Parameters:
ir - The inner radius to use
or - The outer radius to use
spacing - The spacing between loops
lc - The loop count
Throws:
java.lang.IllegalArgumentException - The loop count was invalid

SpringGenerator

public SpringGenerator(float ir,
                       float or,
                       float spacing,
                       int lc,
                       int ifc,
                       int ofc)
Construct a spring with the given radius, spacing and loop count information, and facet count. The loop count must be greater than or equal to 1 and the facet counts must be 3 or more.

Parameters:
ir - The inner radius to use
or - The outer radius to use
spacing - The spacing between loops
lc - The loop count
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 loop count was invalid or facet counts were less than 4
Method Detail

getDimensions

public float[] getDimensions()
Get the dimensions of the spring. These are returned as 2 values of inner and outer radius respectively and then spacing and loop count (converted to a float for this case) 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 spring

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

setLoopDimensions

public void setLoopDimensions(float spacing,
                              int lc)
Change the loop information. Calling this will make the points be re-calculated next time you ask for geometry or normals.

Parameters:
spacing - The spacing between loops
lc - The loop count
Throws:
java.lang.IllegalArgumentException - The loop count was invalid

setFacetCount

public void setFacetCount(int ifc,
                          int ofc)
Change the number of facets used to create this spring. This will cause the geometry to be regenerated next time they are asked for. 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 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