CS 185
Fall 2003
Professor J. L. Sibert
Assignment 4
Assigned: October 13
Due: November 10
Write a class, MyXform3d, for 3d transforms. It will be very similar
to your 2d class, but there are a few differences.
public class MyXform3d {
// constructor
public MyXform3d() {
} // default constructor identity matrix
// instance methods
//applies this MyXform3d to a 3d point
public MyPoint3d apply (MyPoint3d p) {
} // apply
// project to a MyPoint2d, just drop z!!
public MyPoint2d project (MyPoint3d p) {
} // project; this performs an orthographic parallel projection
onto the XY plane.
//preCompose multiplies in dot this stores result in this, i.e. A = B•A
public void preCompose (MyXform3d in){
} // precompose
// reset this MyXform3d to the value specified by the 4x4 matrix in
public void setMatrix(double[][] in){
} //setmatrix
public void setTranslate (double tx, double ty, double tz) {
} //setTranslate 3d
public void setScale (double sx, double sy, double sz) {
} // setScale 3d
public void setRotatez (double theta) {
} // setRotate, note that 3 different methods are necessary for rotation
by euler angles
public void setRotatex (double theta) {
} // setRotate
public void setRotatey (double theta) {
} // setRotate
} // Class MyXform3d
Here is a data set for the famous house.
house 10 7
8.0 16.0 30.0
16.0 10.0 30.0
16.0 0.0 30.0
0.0 0.0 30.0
0.0 10.0 30.0
8.0 16.0 54.0
16.0 10.0 54.0
16.0 0.0 54.0
0.0 0.0 54.0
0.0 10.0 54.0
6 1 5 4 3 2 1
6 6 7 8 9 10 6
5 7 2 3 8 7
5 10 9 4 5 10
5 4 9 8 3 4
5 6 1 2 7 6
5 6 10 5 1 6
The first line identifies the object as a house with 10 vertexes and consisting
of 7 polygons.
The next 10 lines give the x,y, and z coordinates of the vertexes.
The final 7 lines describe the polygons. The first number gives
the number of vertexes for the polygon. This is followed by a list of the
vertexes for that polygon. Each number on the list represents a vertex
from the vertex list. Number 1 is the first vertex (the second line
of the file), number 5 is the 5th vertex (the 6th line of the file) and so
on.
You will also obviously need MyPoint3d and MyPolygon3d (and probably MyLine3d
as well, you'll need it later). They are all similar to their 2d equivalent
but of course they have an additional coordinate. Note: This means MyPolygon3d should have a render method.
The render method should drop Z and render the resulting 2d polygon.
If you put this in a file in the same directory as your HTML file you can use a GWReader object to read it. Reading from files in java is not always easy, so I wrote the GWReader class for you to use.