Flight Club


flightclub.framework3d
Class Tools3d

java.lang.Object
  |
  +--flightclub.framework3d.Tools3d

public class Tools3d
extends java.lang.Object

This class implements static methods for 3d geometry.


Constructor Summary
Tools3d()
           
 
Method Summary
static void add(float[] a, float[] b, float[] c)
          Adds a and b to give the result c.
static float[][] applyTo(float[][] m1, float[][] m2)
           
static void applyTo(float[][] m, float[] a, float[] a_)
          Sets a_ to matrix multiplication of m times a.
static float[][] circleXZ(int npoints, float radius, float[] center)
          Returns a list of points for a circle lying in the XZ plane.
static void cross(float[] a, float[] b, float[] c)
          Makes c equal the cross product of a and b.
static float dot(float[] a, float[] b)
           
static float[][] identity()
          Returns the identity matrix.
static float length(float[] v)
           
static void linearSum(float x, float[] a, float y, float[] b, float[] c)
          Adds x * a and y * b to give the result c.
static void makeUnit(float[] v)
           
static boolean projectYZ(float[] a, float[] a_, float d)
          Projects (x, y, z) to (x_, y_, z_).
static float quickCos(float theta)
           
static float quickSin(float x)
          SPEED - round theta by splitting PI/4 into N steps.
static double rnd(double lower, double upper)
           
static float rnd(float lower, float upper)
           
static float[][] rotateAboutZ(float x)
          Creates a rotation matix that will rotate by x radians about the z axis.
static float[][] rotateX(float[] v)
          Creates a rotation matix that will rotate the given point so that it lies on the x axis.
static float round(float x)
          Rounds a float to n decimal places.
static void scaleBy(float[] v, float scale)
           
static void scaleToLength(float[] v, float length)
           
static void subtract(float[] a, float[] b, float[] c)
          Sets c equal to a minus b.
static java.lang.String toString(float[] p)
          New idea - represent a vector as a float[].
static java.lang.String toString(float[][] m)
           
static float[][] zero()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tools3d

public Tools3d()
Method Detail

circleXZ

public static float[][] circleXZ(int npoints,
                                 float radius,
                                 float[] center)
Returns a list of points for a circle lying in the XZ plane.


identity

public static final float[][] identity()
Returns the identity matrix.


zero

public static final float[][] zero()

dot

public static final float dot(float[] a,
                              float[] b)

rotateX

public static final float[][] rotateX(float[] v)
Creates a rotation matix that will rotate the given point so that it lies on the x axis. We do the transformation in two steps. First, rotate about z axis ( so the point lies in the plane y = 0). Second, rotate about y axis ( so the point lies in the plane z = 0).


rotateAboutZ

public static final float[][] rotateAboutZ(float x)
Creates a rotation matix that will rotate by x radians about the z axis.


applyTo

public static final void applyTo(float[][] m,
                                 float[] a,
                                 float[] a_)
Sets a_ to matrix multiplication of m times a.


applyTo

public static final float[][] applyTo(float[][] m1,
                                      float[][] m2)

projectYZ

public static final boolean projectYZ(float[] a,
                                      float[] a_,
                                      float d)
Projects (x, y, z) to (x_, y_, z_). We are doing a perspective projection with the eye located a distance d along the x axis looking towards the origin. Return false if (x, y, z) falls outside field of view, true otherwise.


add

public static final void add(float[] a,
                             float[] b,
                             float[] c)
Adds a and b to give the result c.


subtract

public static final void subtract(float[] a,
                                  float[] b,
                                  float[] c)
Sets c equal to a minus b. Thus c becomes the vector that takes you from b to a.


linearSum

public static final void linearSum(float x,
                                   float[] a,
                                   float y,
                                   float[] b,
                                   float[] c)
Adds x * a and y * b to give the result c.


length

public static final float length(float[] v)

scaleBy

public static final void scaleBy(float[] v,
                                 float scale)

cross

public static final void cross(float[] a,
                               float[] b,
                               float[] c)
Makes c equal the cross product of a and b. The result has magnitude |a|.|b|.sin(theta) and its direction is perpendicular to the plane defined by a and b. If, as we look at the plane, we turn clockwise to go from a to b then c is pointing away from us.
 
         b <--------   c points 'into' the page
               theta \
                      \
                       \
                        >a
 
        


rnd

public static final double rnd(double lower,
                               double upper)

rnd

public static final float rnd(float lower,
                              float upper)

makeUnit

public static final void makeUnit(float[] v)

scaleToLength

public static final void scaleToLength(float[] v,
                                       float length)

round

public static final float round(float x)
Rounds a float to n decimal places.


toString

public static final java.lang.String toString(float[] p)
New idea - represent a vector as a float[].


toString

public static final java.lang.String toString(float[][] m)

quickSin

public static final float quickSin(float x)
SPEED - round theta by splitting PI/4 into N steps. Then look up a pre computed value from array.


quickCos

public static final float quickCos(float theta)

Dan Burton <danb@dircon.co.uk> | latest update: 20 Sep 2002;