## Class vec2d

```java.lang.Object
vec2d
```

`public class vec2dextends java.lang.Object`

vec2d is a class representing the mathematical concept of two-dimensional vector. In perticular we can consider a vec2d object to be a point in two dimensional space. This class includes the following operations:

• Report the coordinates
• Basic vector operations such as addition and scaling
• Detection of some properties of vector set

This class is written for the Java tutorials of SE2AA4 (Winter 07).

Constructor Summary
```vec2d(double x, double y)```
Creates a new instance of vec2d

Method Summary
`static vec2d` ```add(vec2d v1, vec2d v2)```
Compute the sum of two vectors.
` vec2d` `clone()`
clone another copy of itself this function makes sure the new copy have its own copy of data in memory other than those data of the original vector.
`static boolean` ```coline(vec2d v1, vec2d v2, vec2d v3)```
check if three points are in the same line of two dimensional space.
` double` `getLength()`
Calculate the 2-norm of the vector, which is the square root of the sum of the square of the coordinates.
` double` `getX()`
Get the first coordinate of the vec2d object.
` double` `getY()`
Get the second coordinate of the vec2d object.
`static vec2d` ```mul(double r, vec2d v)```
scale a vector.
` void` `normalize()`
Scale the vector to a unit vector.
`static vec2d` ```proj(vec2d u, vec2d v)```
return the projection of vector u on vector v For two vectors u and v in linear algebra, the projection of u on v is the component of u such that in the same direction of v.
`static double` ```triangleArea(vec2d v1, vec2d v2, vec2d v3)```
Computer the area of a triangle.

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### vec2d

```public vec2d(double x,
double y)```
Creates a new instance of vec2d

Parameters:
`x` - the first coordinate of the vector
`y` - the second coordinate of the vector
Method Detail

### clone

`public vec2d clone()`
clone another copy of itself this function makes sure the new copy have its own copy of data in memory other than those data of the original vector.

Overrides:
`clone` in class `java.lang.Object`
Returns:
an independent copy of the object who call this function.

### getX

`public double getX()`
Get the first coordinate of the vec2d object.

Returns:
the value of first coordinate.

### getY

`public double getY()`
Get the second coordinate of the vec2d object.

Returns:
the value of second coordinate.

### getLength

`public double getLength()`
Calculate the 2-norm of the vector, which is the square root of the sum of the square of the coordinates. In geometry 2-norm is usually considered the magnitude or the length of a vector.

Returns:
2-norm of vector object.

### normalize

```public void normalize()
throws java.lang.IllegalStateException```
Scale the vector to a unit vector. Unit vector is vector of length 1, which means the sum of squares of the first and the second coordinates is one. If the vector is (0,0), this function will throw the java.lang.IllegalStateException.

Throws:
`java.lang.IllegalStateException`

```public static vec2d add(vec2d v1,
vec2d v2)```
Compute the sum of two vectors.

Parameters:
`v1` - the first vector to be added
`v2` - the second vector to be added
Returns:
the coordinate-wise sum of v1 and v2

### mul

```public static vec2d mul(double r,
vec2d v)```
scale a vector. This function will scale an input vector to the input ratio of length, without changing the vector's direction.

Parameters:
`r` - the ratio to scale the vector
`v` - the vector to be scaled
Returns:
the vector obtain by scaling

### coline

```public static boolean coline(vec2d v1,
vec2d v2,
vec2d v3)```
check if three points are in the same line of two dimensional space.

Parameters:
`v1` - the vector representing the first point
`v2` - the vector representing the second point
`v3` - the vector representing the third point
Returns:
true if the three points are at the same line, false otherwise

### proj

```public static vec2d proj(vec2d u,
vec2d v)```
return the projection of vector u on vector v For two vectors u and v in linear algebra, the projection of u on v is the component of u such that in the same direction of v. If w is the projection of u on v, then the dot product of (u-w) and v is zero. A special case is that if v=(0,0), then the projection of u on v is (0,0).

Parameters:
`u` - the vector that we want to find the component by projecting onto the other
`v` - the vector on which u is projected
Returns:
the project of u on v

### triangleArea

```public static double triangleArea(vec2d v1,
vec2d v2,
vec2d v3)```
Computer the area of a triangle. This routine will return the area of triangle having the three input vectors as vertices.

Parameters:
`v1` - the first vertex
`v2` - the second vertex
`v3` - the third vertex
Returns:
the area of the triangle generated by v1, v2 and v3