Project #1: Classes for vectors points Project #1: Classes for vectors, points and rays y
Due: 5:00pm 8/24p /
Submission: send your java sources in a zip file and send it to me
send it to me.
goals
• In this project, you are asked to implement three Java classes Vector Point and Ray for three Java classes, Vector, Point and Ray for geometric primitives.
Y l h ld t th f ti li t d
• Your classes should support the functions listed in the following slides. You are free to design
th i t f l t th
the interface as long as you support the operations.
• For each class, in addition to the required functions, you should also implement
conventional member functions such as equals and toString.
Coordinate system
• Points, vectors and normals are represented with three floating-point coordinate values: x with three floating point coordinate values: x, y, z defined under a coordinate system.
A coordinate system is defined by an origin p
• A coordinate system is defined by an origin po and a frame (linearly independent vectors vi).
A di i
• A vector v= s1v1 +…+snvn represents a direction, while a point p= po+s1v1 +…+snvn represents a
i i Th f l i h bl
position. They are not freely interchangeable.
• We will use left-handed coordinate system.
y z
(0,1,0) (0,0,1)
ld
(0,0,0) (1,0,0)x world space
Vectors
class Vector { public:
public:
<Vector Public Methods>
float x y z;
float x, y, z;
} no need to use selector (getX) and mutator (setX)
because the design gains nothing and adds bulk to its usage
Provided operations: Vector u, v; float a;
+
because the design gains nothing and adds bulk to its usage
v+u, v-u -v
( )
(v==u) a*v, v/a
Dot and cross product
Dot(v, u)
AbsDot(v u)
cos u
v u
v
AbsDot(v, u) Cross(v, u)
Vectors v u v u
sin u
v u
v
Vectors v, u, v×u
form a frame u
θ
v u
x vyuz vzuyu v u
v u
v
θ v
v u
zy vxzuyx vxyuzzu v u
v u
v
Normalization
a=LengthSquared(v) a=Length(v)
a=Length(v)
u=Normalize(v) return a vector, does not normalize in place Take normalize as an example, you can implement it in the following two forms (there are other possibilities):( p )
1. u = v.normalize(); // where normalize is a member function // I personally prefer this one
2. u = Vector.normalize(v); // where v is a static function
Points
Points are different from vectors; given a
coordinate system (p v v v ) a point p and a coordinate system (p0,v1,v2,v3), a point p and a vector v with the same (x,y,z) essentially means
( 1)[ ]T
p=(x,y,z,1)[v1 v2 v3 p0]T v=(x,y,z,0)[v1 v2 v3 p0]T
Vector(Point p); ( p); //converts point to vectorp
Operations for points
Vector v; Point p, q, r; float a;
q q=p+v; // q=p.add(v)
q=p v;
q
q=p-v;
v=q-p; v
r=p+q;
* / p
a*p; p/a; p
(This is only for the operation αp+βq.)
Distance(p,q);
( )
DistanceSquared(p,q);
Rays
class Ray { public:
public:
Point o;
Vector d;
Vector d;
float mint, maxt;
int depth;
Initialized as a small and a large number respectively
int depth;
};
number respectively (how many times the ray has bounced, ignore for now)
maxt
Ray r(o, d);
Point p=r.at(t);
d
i t
maxt
t t
t) 0
( o d
r
o mint ( )