Next: 2D Vector Geometry Functions Up: 2D and 3D vector Previous: 3D Matrix Algebra Functions   Contents

## 2D Vector Algebra Functions

These have similar functionality to the corresponding 3D functions. Only those which are different are commented on here.

```void *vec2_alloc()

void *vec2_make(Vec2 u)

void vec2_free(void *v)

Vec2 vec2(double x, double y)

Vec2 vec2_zero()

Vec2 vec2_ex()

Vec2 vec2_ey()

void vec2_comps(Vec2 v, double *x, double *y)

Macro vec2_x(Vec2 v)

Macro vec2_y(Vec2 v)

double vec2_get_x(Vec2 v)

double vec2_get_y(Vec2 v)

Vec2 vec2_sum(Vec2 v, Vec2 w)

Vec2 vec2_sum3(Vec2 u, Vec2 v, Vec2 w)

Vec2 vec2_sum4(Vec2 u, Vec2 v, Vec2 w, Vec2 x)

Vec2 vec2_minus(Vec2 v)

Vec2 vec2_diff(Vec2 v, Vec2 w)

Vec2 vec2_times(double k, Vec2 v)

double vec2_dot(Vec2 v, Vec2 w)

double vec2_mod(Vec2 v)

double vec2_sqrmod(Vec2 v)

double vec2_modunit(Vec2 v, Vec2 *e)

Vec2 vec2_unit(Vec2 v)

double vec2_dist(Vec2 v, Vec2 w)

double vec2_sqrdist(Vec2 v, Vec2 w)

void vec2_print(FILE *fp, Vec2 v)

void vec2_pprint(FILE *fp, char *msg, Vec2 v)

void vec2_format(Vec2 v)
```

```void vec2_basis(Vec 2 up, Vec2 *ex, Vec2 *ey)
```
sets *ex and *ey to basis vectors with the y-vector in the direction up and the x-vector rotated 90 degrees clockwise from this.

```Vec2 vec2_perp(Vec2 v)
```
Returns a unit vector perpendicular to v rotated 90 degrees anticlockwise from v.

```double vec2_cross(Vec2 v, Vec2 w)
```
Returns the scalar cross product vx*wy-vy*wx of v and w. (This is the signed are of the parallelogram they span).

```double vec2_angle(Vec2 v, Vec2 w)
```
Returns the anti-clockwise angle from v to w (lies between -pi and pi).

Next: 2D Vector Geometry Functions Up: 2D and 3D vector Previous: 3D Matrix Algebra Functions   Contents
root 2019-03-24