SciLib.Grp
Class Graphics3D

java.lang.Object
  extended by SciLib.Grp.Graphics2D
      extended by SciLib.Grp.Graphics3D

public class Graphics3D
extends Graphics2D

This class contains some methods to draw a 3D graphics.


Field Summary
 
Fields inherited from class SciLib.Grp.Graphics2D
height, Pi, width
 
Constructor Summary
Graphics3D()
          Constructor, set view to default
 
Method Summary
 void box(java.awt.Graphics g, double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
          Make a box for coordinate system
 void box(java.awt.Graphics g, double xmin, double ymin, double zmin, double xmax, double ymax, double zmax, boolean coord)
          Make a box for coordinate system
 void changeView(vector a, vector f, vector u, double angle)
          change 3D View
 void coord3D(java.awt.Graphics g, double minx, double miny, double minz, double maxx, double maxy, double maxz)
          Make a 3D coordinate system
 void coord3D(java.awt.Graphics g, vector left, vector right)
          Make a 3D coordinate system
 void defaultView()
          set the view matrix to the default view
 double getAngle()
          get the view angle
 vector getAt()
          get the at point
 vector getFrom()
          get the from point
 double getScale()
          get scale factor
 vector getUp()
          get the up point
 matrix getView3D()
          Return the view matrix.
 void grid(java.awt.Graphics g, double minx, double miny, double minz, double maxx, double maxy, double maxz)
          Draw the coordinate system
 void lineTo(java.awt.Graphics g, double x, double y, double z)
          draw line from the current position to a point (x,y, z)
 void moveTo(double x, double y, double z)
          move pen to a real position (x, y, z)
 matrix rotation(double theta, int n)
          Make 3D rotation matrix by an angle Rotate the axes anti-clockwise through an angle theta
 matrix scale(double[] scaleVec)
          Make 3D scale matrix by vector scaleVec
 void screenPos(java.awt.Point ip, double x, double y, double z)
          Compute the position on the screen, values are stored in ip
 void screenPos(java.awt.Point ip, vector x)
          Compute the position on the screen, values are stored in ip
 void SetAngle(double angle)
          change the viewAngle
 void setEyes()
          Compute transformations to make an eye coordinate system
 void setFrom(vector a)
          set the "from" point to the new postion a
 void setScaleFactor(double s)
          set a new scale factor
 void setView3D(matrix V)
          Change the view matrix.
 void transform(double[] p, matrix V, double[] np)
          Compute the eye coordinate system from a point p in a 3D space
 void transform(double x, double y, double z, matrix V, double[] np)
          Compute the eye coordinate system from a point (x,y,z) in a 3D space
 vector transform(vector x, matrix V)
          Compute the eye coordinate system from a point x in a 3D space
 matrix translate(double[] transVec)
          Make 3D translation matrix by vector transVec.
static vector vecCross(vector a, vector b)
          Compute the cross product of the two vector in 3D space
 
Methods inherited from class SciLib.Grp.Graphics2D
box, changeWindowSize, changeWindowSize, coord, coord2D, coord2D, coord2D, drawLine, getView2D, halfGrid, lineTo, moveTo, rotation, screenPos, setView2D, setView2D
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Graphics3D

public Graphics3D()
Constructor, set view to default

Method Detail

getView3D

public matrix getView3D()
Return the view matrix.

Returns:
A matrix

setView3D

public void setView3D(matrix V)
Change the view matrix.

Parameters:
V - the new view matrix

defaultView

public void defaultView()
set the view matrix to the default view


SetAngle

public void SetAngle(double angle)
change the viewAngle

Parameters:
angle - the new viewAngle in degrees

setFrom

public void setFrom(vector a)
set the "from" point to the new postion a

Parameters:
a - the new "from" point

vecCross

public static vector vecCross(vector a,
                              vector b)
Compute the cross product of the two vector in 3D space

Parameters:
a - a vector
b - a vector
Returns:
a vector

setEyes

public void setEyes()
Compute transformations to make an eye coordinate system


transform

public void transform(double x,
                      double y,
                      double z,
                      matrix V,
                      double[] np)
Compute the eye coordinate system from a point (x,y,z) in a 3D space

Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point
z - the z-coordinate of the point
V - the view matrix
np - an array that contains the eye coordinates

transform

public void transform(double[] p,
                      matrix V,
                      double[] np)
Compute the eye coordinate system from a point p in a 3D space

Parameters:
p - the point in a 3D sapce
V - the view matrix
np - an array that contains the eye coordinates

transform

public vector transform(vector x,
                        matrix V)
Compute the eye coordinate system from a point x in a 3D space

Parameters:
x - the point in a 3D sapce
V - the view matrix
Returns:
a vector that contains the eye coordinates

coord3D

public void coord3D(java.awt.Graphics g,
                    double minx,
                    double miny,
                    double minz,
                    double maxx,
                    double maxy,
                    double maxz)
Make a 3D coordinate system

Parameters:
g - the Graphics object
minx - the minimum x-coordinate
miny - the minimum y-coordinate
minz - the minimum z-coordinate
maxx - the maximum x-coordinate
maxy - the maximum y-coordinate
maxz - the maximum z-coordinate

coord3D

public void coord3D(java.awt.Graphics g,
                    vector left,
                    vector right)
Make a 3D coordinate system

Parameters:
g - the Graphics object
left - the left point that contains the minimum coordinates
right - the right point that contains the maximum coordinates

screenPos

public void screenPos(java.awt.Point ip,
                      double x,
                      double y,
                      double z)
Compute the position on the screen, values are stored in ip

Parameters:
ip - A Point object
x - The x-coordinate
y - The y-coordinate
z - The z-coordinate

screenPos

public void screenPos(java.awt.Point ip,
                      vector x)
Compute the position on the screen, values are stored in ip

Parameters:
ip - A Point object
x - The point in a 3D space

moveTo

public void moveTo(double x,
                   double y,
                   double z)
move pen to a real position (x, y, z)

Parameters:
x - The x-coordinate
y - The y-coordinate
z - The z-coordinate

lineTo

public void lineTo(java.awt.Graphics g,
                   double x,
                   double y,
                   double z)
draw line from the current position to a point (x,y, z)

Parameters:
g - Graphics
x - The x-coordinate
y - The y-coordinate
z - The z-coordinate

box

public void box(java.awt.Graphics g,
                double xmin,
                double ymin,
                double zmin,
                double xmax,
                double ymax,
                double zmax)
Make a box for coordinate system

Parameters:
g - Graphics
xmin - The minimum of the x-coordinates
ymin - The minimum of the y-coordinates
zmin - The minimum of the z-coordinates
xmax - The maximum of the x-coordinates
ymax - The maximum of the y-coordinates
zmax - The maximum of the z-coordinates

box

public void box(java.awt.Graphics g,
                double xmin,
                double ymin,
                double zmin,
                double xmax,
                double ymax,
                double zmax,
                boolean coord)
Make a box for coordinate system

Parameters:
g - Graphics
xmin - The minimum of the x-coordinates
ymin - The minimum of the y-coordinates
zmin - The minimum of the z-coordinates
xmax - The maximum of the x-coordinates
ymax - The maximum of the y-coordinates
zmax - The maximum of the z-coordinates

grid

public void grid(java.awt.Graphics g,
                 double minx,
                 double miny,
                 double minz,
                 double maxx,
                 double maxy,
                 double maxz)
Draw the coordinate system

Overrides:
grid in class Graphics2D
Parameters:
g - Graphics
minx - the minimum x-coordinate
miny - the minimum y-coordinate
minz - the minimum z-coordinate
maxx - the maximum x-coordinate
maxy - the maximum y-coordinate
maxz - the maximum z-coordinate

changeView

public void changeView(vector a,
                       vector f,
                       vector u,
                       double angle)
change 3D View

Parameters:
a - A vector, the at point
f - A vector, the from point
u - A vector, the up point
angle - A double value, the view angle in degrees

getScale

public double getScale()
get scale factor

Returns:
A double value

setScaleFactor

public void setScaleFactor(double s)
set a new scale factor

Parameters:
s - A double value, the new scale factor

getAt

public vector getAt()
get the at point

Returns:
A vector

getFrom

public vector getFrom()
get the from point

Returns:
A vector

getUp

public vector getUp()
get the up point

Returns:
A vector

getAngle

public double getAngle()
get the view angle

Returns:
A double value

translate

public matrix translate(double[] transVec)
Make 3D translation matrix by vector transVec. Translate the origin by vector (-tx,-ty,-tz) Translate a point by using (tx,ty,tz)

Overrides:
translate in class Graphics2D
Parameters:
transVec - the translate vector

scale

public matrix scale(double[] scaleVec)
Make 3D scale matrix by vector scaleVec

Overrides:
scale in class Graphics2D
Parameters:
scaleVec - the scale vector

rotation

public matrix rotation(double theta,
                       int n)
Make 3D rotation matrix by an angle Rotate the axes anti-clockwise through an angle theta

Parameters:
theta - the rotation angle in degrees
n - An integer value, n=1 : rotate about x-axis, n = 2 -->y-axis og n = 3 -->z-axis