ARITH3(3)
π ARITH3(3) π β operations on 3-d points and planes
okay bestie, welcome to the ARITH3(3) page from the Library Functions Manual β¨ this one is all about doing arithmetic on points and planes in affine or projective 3-space, and it is honestly lowkey iconic π
πΈ 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 is
typedef struct Point3 Point3;
struct Point3{
double x, y, z, w;
};
Routines whose names end in 3 operate on vectors or ordinary points in affine 3-space, represented by their Euclidean (x,y,z) coordinates. They assume w=1 in their arguments, and set w=1 in their results. π«Ά
β¨ the ...3 routines β¨
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 thaneps?dot3β dot product.cross3β cross product.len3β distance to the origin.dist3β distance between two points.unit3β a unit vector parallel top.midpt3β the midpoint of line segmentpq.lerp3β linear interpolation betweenpandq.reflect3β the reflection of pointpin the segment joiningp0andp1.nearseg3β the closest point totestpon segmentp0 p1.pldist3β the distance frompto segmentp0 p1.vdiv3β Vector divide β the length of the component ofaparallel tob, in units of the length ofb.vrem3β Vector remainder β the component ofaperpendicular tob. Ignoring roundoff, we haveeqpt3(add3(mul3(b, vdiv3(a, b)), vrem3(a, b)), a).
π§ plane + point conversions (the extra-cryptic names) π§
The following routines convert amongst various representations of points and planes. Planes are represented identically to points, by duality; a point p is on a plane q whenever p.x*q.x+p.y*q.y+p.z*q.z+p.w*q.w=0. Although when dealing with affine points we assume p.w=1, we can't make the same assumption for planes. the names of these routines are extra-cryptic β they contain an f (for face) to indicate a plane, p for a point and n for a normal vector. The number 2 abbreviates the word to. The number 3 reminds us, as before, that we're dealing with affine points. Thus pn2f3 takes a point and a normal vector and returns the corresponding plane. π«
pn2f3β compute the plane passing throughpwith normaln.ppp2f3β compute the plane passing through three points.fff2p3β compute the intersection point of three planes.
π
the ...4 routines π
The names of the following routines end in 4 because they operate on points in projective 4-space, represented by their homogeneous coordinates.
pdiv4β Perspective division. Dividep.wintop's coordinates, converting to affine coordinates. Ifp.wis zero, the result is the same as the argument.add4β add the coordinates of two points.sub4β subtract the coordinates of two points.
bestie, thatp.wzero case inpdiv4is the special little moment where the result is the same as the argument β no cap, that's literally what the page says π
π SOURCE π
/src/libgeometry
π SEE ALSO π
and that's the ARITH3(3) footer moment: this page is from the Library Functions Manual, source /src/libgeometry, and there is no version/date stamped on it β just the manual name β so here's your cute undated sign-off, bestie ππ«Άβ¨
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms