ARITH3(2)ARITH3(2)

## NAME

add3, sub3, neg3, div3, mul3, eqpt3, closept3, dot3, cross3, len3, dist3, unit3, midpt3, lerp3, reflect3, nearseg3, pldist3, vdiv3, vrem3, pn2f3, ppp2f3, fff2p3, pdiv4, add4, sub4 – operations on 3-d points and planes

## SYNOPSIS

`#include <draw.h>
`

`#include <geometry.h>
`

`Point3 add3(Point3 a, Point3 b)
`

`Point3 sub3(Point3 a, Point3 b)
`

`Point3 neg3(Point3 a)
`

`Point3 div3(Point3 a, double b)
`

`Point3 mul3(Point3 a, double b)
`

`int eqpt3(Point3 p, Point3 q)
`

`int closept3(Point3 p, Point3 q, double eps)
`

`double dot3(Point3 p, Point3 q)
`

`Point3 cross3(Point3 p, Point3 q)
`

`double len3(Point3 p)
`

`double dist3(Point3 p, Point3 q)
`

`Point3 unit3(Point3 p)
`

`Point3 midpt3(Point3 p, Point3 q)
`

`Point3 lerp3(Point3 p, Point3 q, double alpha)
`

`Point3 reflect3(Point3 p, Point3 p0, Point3 p1)
`

`Point3 nearseg3(Point3 p0, Point3 p1, Point3 testp)
`

`double pldist3(Point3 p, Point3 p0, Point3 p1)
`

`double vdiv3(Point3 a, Point3 b)
`

`Point3 vrem3(Point3 a, Point3 b)
`

`Point3 pn2f3(Point3 p, Point3 n)
`

`Point3 ppp2f3(Point3 p0, Point3 p1, Point3 p2)
`

`Point3 fff2p3(Point3 f0, Point3 f1, Point3 f2)
`

`Point3 pdiv4(Point3 a)
`

`Point3 add4(Point3 a, Point3 b)
`

`Point3 sub4(Point3 a, Point3 b)
`

## DESCRIPTION

These routines do arithmetic on points and planes in affine or projective 3-space.
Type
`Point3`

typedef struct Point3 Point3; struct Point3{ double x, y, z, w; };

Routines whose names end in
`3``(x,y,z)``w=1``w=1`

Description

`add3`

Add the coordinates of two points.

`sub3`

Subtract coordinates of two points.

`neg3`

Negate the coordinates of a point.

`mul3`

Multiply coordinates by a scalar.

`div3`

Divide coordinates by a scalar.

`eqpt3`

Test two points for exact equality.

`closept3`

Is the distance between two points smaller than
*eps*?

`dot3`

Dot product.

`cross3`

Cross product.

`len3`

Distance to the origin.

`dist3`

Distance between two points.

`unit3`

A unit vector parallel to
*p*.

`midpt3`

The midpoint of line segment
*pq*.

`lerp3`

Linear interpolation between
*p**q*.

`reflect3`

The reflection of point
*p**p0**p1*.

`nearseg3`

The closest point to
*testp**p0 p1* .

`pldist3`

The distance from
*p**p0 p1* .

`vdiv3`

Vector divide * the length of the component of *
*a**b*,*b*.

`vrem3`

Vector remainder * the component of *
*a**b*.`eqpt3(add3(mul3(b, vdiv3(a, b)), vrem3(a, b)), a)` .

The following routines convert amongst various representations of points
and planes. Planes are represented identically to points, by duality;
a point
`p``q``p.x*q.x+p.y*q.y+p.z*q.z+p.w*q.w=0`.`p.w=1`,`f``p``n``2``3``pn2f3`

Description

`pn2f3`

Compute the plane passing through
*p**n*.

`ppp2f3`

Compute the plane passing through three points.

`fff2p3`

Compute the intersection point of three planes.

The names of the following routines end in
`4`

Perspective division. Divide
`p.w`*p*’s`p.w`

Add the coordinates of two points.

Subtract the coordinates of two points.

## SOURCE

`/sys/src/libgeometry`