# Computer Graphics

## Lab Exercise 1: Points and Vectors

The purpose of this work is to construct a module that deals with 3D points and vectors. This should be represented properly as an abstract data type and will be used in subsequent CG work. Java is used.

Define the data structures for a 3D point and vector, called Point3D and Vector3D. Then define the mathematical functions for (a) pointwise distance (b) vector L2 norm (c) vector dot product (d) vector cross product (e) vector normalisation.

The class design is provided for you. It is essential that you follow the specifications since all the following labs rely on them.

#### Point3D.java

```public class Point3D
{
public double x,y,z;

public Point3D(double X,double Y,double Z){}

public double distance(Point3D p){}

public String toString(){/* Make it look nice to save your debugging time! */}
}
```

#### Vector3D.java

```import static java.lang.Math.*;  /* Now you can use math functions without the Math. prefix */

public class Vector3D implements Cloneable
{
public double x,y,z;

public Vector3D(double X, double Y, double Z){}

public String toString(){/* Make it look nice to save your debugging time! */}

public Vector3D clone() throws CloneNotSupportedException{}

public double L2norm(){/* L2 norm is the length of the vector */}

public double dotProduct(Vector3D v){}

public Vector3D crossProduct(Vector3D v){}

public void normalize(){/* to normalise a vector is to change the vector length to 1 while keeping the vector direction the same */}
}
```

#### Notes

This module will be extended as the course continues. Nevertheless you should try to finish it completely this week. Test your code out by computing the answers to the questions on the Maths warm-up exercises.