toxi.geom
Class Sphere

java.lang.Object
  extended by toxi.geom.Vec3D
      extended by toxi.geom.Sphere
All Implemented Interfaces:
java.lang.Comparable<Vec3D>

public class Sphere
extends Vec3D


Nested Class Summary
 
Nested classes/interfaces inherited from class toxi.geom.Vec3D
Vec3D.Axis
 
Field Summary
 float radius
           
 
Fields inherited from class toxi.geom.Vec3D
MAX_VALUE, MIN_VALUE, x, X_AXIS, y, Y_AXIS, z, Z_AXIS, ZERO
 
Constructor Summary
Sphere()
           
Sphere(Sphere s)
           
Sphere(Vec3D v, float r)
           
 
Method Summary
 boolean containsPoint(Vec3D p)
           
 float[] intersectRay(Ray3D ray)
          Alternative to SphereIntersectorReflector.
 boolean intersectSphereTriangle(Triangle t, Vec3D result)
          Considers the current vector as centre of a collision sphere with radius r and checks if the triangle abc intersects with this sphere.
 Vec3D tangentPlaneNormalAt(Vec3D q)
          Calculates the normal vector on the sphere in the direction of the current point.
 
Methods inherited from class toxi.geom.Vec3D
abs, add, add, addSelf, addSelf, angleBetween, angleBetween, clear, closestPointOnLine, compareTo, constrain, constrain, copy, cross, crossInto, crossSelf, distanceTo, distanceToSquared, dot, equals, equalsWithTolerance, floor, frac, fromXYTheta, fromXZTheta, fromYZTheta, getAbs, getComponent, getConstrained, getFloored, getFrac, getInverted, getLimited, getNormalized, getNormalizedTo, getReciprocal, getRotatedAroundAxis, getRotatedX, getRotatedY, getRotatedZ, getSignum, hashCode, headingXY, headingXZ, headingYZ, interpolateTo, interpolateTo, interpolateToSelf, interpolateToSelf, invert, isInAABB, isInAABB, isZeroVector, jitter, jitter, jitter, limit, magnitude, magSquared, max, maxSelf, min, minSelf, modSelf, modSelf, normalize, normalizeTo, randomVector, randomVector, reciprocal, rotateAroundAxis, rotateX, rotateY, rotateZ, scale, scale, scale, scaleSelf, scaleSelf, scaleSelf, set, set, setComponent, setXY, signum, sub, sub, subSelf, subSelf, to2DXY, to2DXZ, to2DYZ, toArray, toCartesian, toSpherical, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

radius

public float radius
Constructor Detail

Sphere

public Sphere()

Sphere

public Sphere(Sphere s)

Sphere

public Sphere(Vec3D v,
              float r)
Method Detail

containsPoint

public boolean containsPoint(Vec3D p)

intersectRay

public float[] intersectRay(Ray3D ray)
Alternative to SphereIntersectorReflector. Computes primary & secondary intersection points of this sphere with the given ray. If no intersection is found the method returns null. In all other cases, the returned array will contain the distance to the primary intersection point (i.e. the closest in the direction of the ray) as its first index and the other one as its second. If any of distance values is negative, the intersection point lies in the opposite ray direction (might be useful to know). To get the actual intersection point coordinates, simply pass the returned values to Ray3D.getPointAtDistance(float).

Parameters:
ray -
Returns:
2-element float array of intersection points or null if ray doesn't intersect sphere at all.

intersectSphereTriangle

public boolean intersectSphereTriangle(Triangle t,
                                       Vec3D result)
Considers the current vector as centre of a collision sphere with radius r and checks if the triangle abc intersects with this sphere. The Vec3D p The point on abc closest to the sphere center is returned via the supplied result vector argument.

Parameters:
t - triangle to check for intersection
result - a non-null vector for storing the result
Returns:
true, if sphere intersects triangle ABC

tangentPlaneNormalAt

public Vec3D tangentPlaneNormalAt(Vec3D q)
Calculates the normal vector on the sphere in the direction of the current point.

Parameters:
q -
Returns:
a unit normal vector to the tangent plane of the ellipsoid in the point.