net.algart.model3d.common.movement.model
Class ElasticBall

java.lang.Object
  extended by net.algart.model3d.common.movement.model.ElasticBall
All Implemented Interfaces:
HavingCenter, HavingInteractionRadius, HavingMass, HavingVelocity, Item, Spherical

public final class ElasticBall
extends java.lang.Object
implements Item, HavingCenter, Spherical, HavingInteractionRadius, HavingMass, HavingVelocity

Elastic ball: a sphere with some density ρ and elasticity modulus μ, which can interact with other balls and items as a solid body. The basic types of interaction, applying to this item, are ElasticBallsInteractionRule, ElasticBallByBunkerWallInteractionRule, EarthGravitationRule and PhysicalMediumResistanceRule.

Any elastic ball has a mass m=4/3πr3ρ, ρ is the density of the ball. Also an elastic ball has an elasticity modulus μ, which affects the force of interaction with other solid items: if two items (for example, balls) little intersects, the corresponding interaction rule produces a repulsion force, depending on the volume of intersection, and μ is the proportionality coefficient in that dependence. At last, any elastic ball has a friction coefficient, which is used while calculating friction force between two items.

Any elastic ball has an interaction radius, which is just equal to its usual radius. In other words, it is supposed that elastic ball can interact with other item only if they intersect.

This class is not thread-safe, but is thread-compatible and can be synchronized manually if multithread access is necessary.

AlgART Laboratory 2010

Since:
JDK 1.5
Version:
1.0
Author:
Daniel Alievsky

Constructor Summary
Constructor and Description
ElasticBall(double x, double y, double z, double radius, double density, double elasticityModulus, double frictionCoefficient)
          Creates new elastic ball with the specified parameters.
 
Method Summary
Modifier and Type Method and Description
 double getCenterX()
          Returns x-coordinate of the item's center.
 double getCenterY()
          Returns y-coordinate of the item's center.
 double getCenterZ()
          Returns z-coordinate of the item's center.
 float getDensity()
          Returns the density ρ of this ball.
 double getElasticityModulus()
          Returns the elasticity modulus.
 float getFrictionCoefficient()
          Returns the friction coefficient.
 double getMass()
          Returns the mass of this item.
 double getMaxInteractionRadius()
          Returns the interaction radius R: maximal distance from the center where this object can affect to other item, also implementing this interface.
 double getRadius()
          Returns the radius of this spherical item.
 double getVelocityX()
          Returns x-component of the velocity of the item's center.
 double getVelocityY()
          Returns y-component of the velocity of the item's center.
 double getVelocityZ()
          Returns z-component of the velocity of the item's center.
 boolean intersects(Spherical other)
          Returns true if and only if this sphere intersects the specified other sphere, i.e.
 boolean isInfinite()
          Returns true if at least one of 3 coordinates of the item's center is Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY.
 boolean isNaN()
          Returns true if at least one of 3 coordinates of the item's center is NaN.
 void setCenter(double x, double y, double z)
          Sets all coordinates of the item's center.
 void setCenterX(double x)
          Sets x-coordinate of the item's center.
 void setCenterY(double y)
          Sets y-coordinate of the item's center.
 void setCenterZ(double z)
          Sets z-coordinate of the item's center.
 void setDensity(float density)
          Sets the density ρ of this ball.
 void setRadius(double radius)
          Sets the radius of this ball.
 void setVelocity(double velocityX, double velocityY, double velocityZ)
          Sets all components of the velocity of the item's center.
 void setVelocityX(double velocityX)
          Sets x-component of the velocity of the item's center.
 void setVelocityY(double velocityY)
          Sets y-component of the velocity of the item's center.
 void setVelocityZ(double velocityZ)
          Sets z-component of the velocity of the item's center.
 double squareOfDistance(HavingCenter other)
          Returns the square of the distance between this item's center and the center of the specified item.
 java.lang.String toString()
          Returns a brief string description of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ElasticBall

public ElasticBall(double x,
                   double y,
                   double z,
                   double radius,
                   double density,
                   double elasticityModulus,
                   double frictionCoefficient)
Creates new elastic ball with the specified parameters. The velocity of the created ball is zero (0 vector).

Parameters:
x - initial x-coordinate of the center.
y - initial y-coordinate of the center.
z - initial z-coordinate of the center.
radius - the radius of the new ball.
density - the density ρ of the new ball.
elasticityModulus - the elasticity modulus μ of the new ball (cannot be changed in future).
frictionCoefficient - the friction coefficient of the new ball (cannot be changed in future).
Throws:
java.lang.IllegalArgumentException - if the passed radius is negative (< 0).
Method Detail

getDensity

public float getDensity()
Returns the density ρ of this ball.

Returns:
the density ρ of this ball.

setDensity

public void setDensity(float density)
Sets the density ρ of this ball.

Parameters:
density - new density ρ of this ball.

getElasticityModulus

public double getElasticityModulus()
Returns the elasticity modulus.

Returns:
the elasticity modulus.

getFrictionCoefficient

public float getFrictionCoefficient()
Returns the friction coefficient.

Returns:
the friction coefficient.

getCenterX

public final double getCenterX()
Description copied from interface: HavingCenter
Returns x-coordinate of the item's center.

Specified by:
getCenterX in interface HavingCenter
Returns:
x-coordinate of the item's center.

getCenterY

public final double getCenterY()
Description copied from interface: HavingCenter
Returns y-coordinate of the item's center.

Specified by:
getCenterY in interface HavingCenter
Returns:
y-coordinate of the item's center.

getCenterZ

public final double getCenterZ()
Description copied from interface: HavingCenter
Returns z-coordinate of the item's center.

Specified by:
getCenterZ in interface HavingCenter
Returns:
z-coordinate of the item's center.

setCenterX

public void setCenterX(double x)
Description copied from interface: HavingCenter
Sets x-coordinate of the item's center.

Specified by:
setCenterX in interface HavingCenter
Parameters:
x - new x-coordinate of the new item's center.

setCenterY

public void setCenterY(double y)
Description copied from interface: HavingCenter
Sets y-coordinate of the item's center.

Specified by:
setCenterY in interface HavingCenter
Parameters:
y - new y-coordinate of the new item's center.

setCenterZ

public void setCenterZ(double z)
Description copied from interface: HavingCenter
Sets z-coordinate of the item's center.

Specified by:
setCenterZ in interface HavingCenter
Parameters:
z - new z-coordinate of the new item's center.

setCenter

public void setCenter(double x,
                      double y,
                      double z)
Description copied from interface: HavingCenter
Sets all coordinates of the item's center.

Specified by:
setCenter in interface HavingCenter
Parameters:
x - new x-coordinate of the new item's center.
y - new y-coordinate of the new item's center.
z - new z-coordinate of the new item's center.

isNaN

public boolean isNaN()
Description copied from interface: HavingCenter
Returns true if at least one of 3 coordinates of the item's center is NaN.

Specified by:
isNaN in interface HavingCenter
Returns:
whether at least one of 3 coordinates of the item's center is NaN.

isInfinite

public boolean isInfinite()
Description copied from interface: HavingCenter
Returns true if at least one of 3 coordinates of the item's center is Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY.

Specified by:
isInfinite in interface HavingCenter
Returns:
whether at least one of 3 coordinates of the item's center is infinite.

squareOfDistance

public final double squareOfDistance(HavingCenter other)
Description copied from interface: HavingCenter
Returns the square of the distance between this item's center and the center of the specified item. Equivalent to the following formula: (otherX-x)*(otherX-x) + (otherY-y)*(otherY-y) + (otherZ-z)*(other-z), where x, y, z are coordinates of the center of this item and otherX, otherY, otherZ are coordinates of the center of the argument.

Specified by:
squareOfDistance in interface HavingCenter
Parameters:
other - some other item, which also has a center.
Returns:
the square of the distance between centers of this and the other items.

getRadius

public double getRadius()
Description copied from interface: Spherical
Returns the radius of this spherical item.

Specified by:
getRadius in interface Spherical
Returns:
the radius of this spherical item.

setRadius

public void setRadius(double radius)
Sets the radius of this ball.

Parameters:
radius - new radius of this ball.

intersects

public boolean intersects(Spherical other)
Description copied from interface: Spherical
Returns true if and only if this sphere intersects the specified other sphere, i.e. if the sum of their radii is greater than the distance between centers.

Specified by:
intersects in interface Spherical
Parameters:
other - some other spherical item.
Returns:
whether the specified sphere intersects this one.

getMaxInteractionRadius

public double getMaxInteractionRadius()
Description copied from interface: HavingInteractionRadius
Returns the interaction radius R: maximal distance from the center where this object can affect to other item, also implementing this interface. Can return Double.POSITIVE_INFINITY: it means the same as if the object does not implement this interface.

Specified by:
getMaxInteractionRadius in interface HavingInteractionRadius
Returns:
the interaction radius R.

getMass

public double getMass()
Description copied from interface: HavingMass
Returns the mass of this item.

Specified by:
getMass in interface HavingMass
Returns:
the mass of this item.

getVelocityX

public double getVelocityX()
Description copied from interface: HavingVelocity
Returns x-component of the velocity of the item's center.

Specified by:
getVelocityX in interface HavingVelocity
Returns:
x-component of the velocity of the item's center.

getVelocityY

public double getVelocityY()
Description copied from interface: HavingVelocity
Returns y-component of the velocity of the item's center.

Specified by:
getVelocityY in interface HavingVelocity
Returns:
y-component of the velocity of the item's center.

getVelocityZ

public double getVelocityZ()
Description copied from interface: HavingVelocity
Returns z-component of the velocity of the item's center.

Specified by:
getVelocityZ in interface HavingVelocity
Returns:
z-component of the velocity of the item's center.

setVelocityX

public void setVelocityX(double velocityX)
Description copied from interface: HavingVelocity
Sets x-component of the velocity of the item's center.

Specified by:
setVelocityX in interface HavingVelocity
Parameters:
velocityX - new x-component of the new velocity of the item's center.

setVelocityY

public void setVelocityY(double velocityY)
Description copied from interface: HavingVelocity
Sets y-component of the velocity of the item's center.

Specified by:
setVelocityY in interface HavingVelocity
Parameters:
velocityY - new y-component of the new velocity of the item's center.

setVelocityZ

public void setVelocityZ(double velocityZ)
Description copied from interface: HavingVelocity
Sets z-component of the velocity of the item's center.

Specified by:
setVelocityZ in interface HavingVelocity
Parameters:
velocityZ - new z-component of the new velocity of the item's center.

setVelocity

public void setVelocity(double velocityX,
                        double velocityY,
                        double velocityZ)
Description copied from interface: HavingVelocity
Sets all components of the velocity of the item's center.

Specified by:
setVelocity in interface HavingVelocity
Parameters:
velocityX - new x-component of the new velocity of the item's center.
velocityY - new y-component of the new velocity of the item's center.
velocityZ - new z-component of the new velocity of the item's center.

toString

public java.lang.String toString()
Returns a brief string description of this object.

The result of this method may depend on implementation.

Overrides:
toString in class java.lang.Object
Returns:
a brief string description of this object.