268 lines · 4.3 KB · Text
RawDownload
.TH ARITH3 2.SH NAMEadd3, 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.SH SYNOPSIS.B#include <draw.h>.br.B#include <geometry.h>.PP.BPoint3 add3(Point3 a, Point3 b).PP.BPoint3 sub3(Point3 a, Point3 b).PP.BPoint3 neg3(Point3 a).PP.BPoint3 div3(Point3 a, double b).PP.BPoint3 mul3(Point3 a, double b).PP.Bint eqpt3(Point3 p, Point3 q).PP.Bint closept3(Point3 p, Point3 q, double eps).PP.Bdouble dot3(Point3 p, Point3 q).PP.BPoint3 cross3(Point3 p, Point3 q).PP.Bdouble len3(Point3 p).PP.Bdouble dist3(Point3 p, Point3 q).PP.BPoint3 unit3(Point3 p).PP.BPoint3 midpt3(Point3 p, Point3 q).PP.BPoint3 lerp3(Point3 p, Point3 q, double alpha).PP.BPoint3 reflect3(Point3 p, Point3 p0, Point3 p1).PP.BPoint3 nearseg3(Point3 p0, Point3 p1, Point3 testp).PP.Bdouble pldist3(Point3 p, Point3 p0, Point3 p1).PP.Bdouble vdiv3(Point3 a, Point3 b).PP.BPoint3 vrem3(Point3 a, Point3 b).PP.BPoint3 pn2f3(Point3 p, Point3 n).PP.BPoint3 ppp2f3(Point3 p0, Point3 p1, Point3 p2).PP.BPoint3 fff2p3(Point3 f0, Point3 f1, Point3 f2).PP.BPoint3 pdiv4(Point3 a).PP.BPoint3 add4(Point3 a, Point3 b).PP.BPoint3 sub4(Point3 a, Point3 b).SH DESCRIPTIONThese routines do arithmetic on points and planes in affine or projective 3-space.Type.B Point3is.IP.EX.ta 6ntypedef struct Point3 Point3;struct Point3{	double x, y, z, w;};.EE.PPRoutines whose names end in.B 3operate on vectors or ordinary points in affine 3-space, represented by their Euclidean.B (x,y,z)coordinates.(They assume.B w=1in their arguments, and set.B w=1in their results.).TF reflect3.TPNameDescription.TP.B add3Add the coordinates of two points..TP.B sub3Subtract coordinates of two points..TP.B neg3Negate the coordinates of a point..TP.B mul3Multiply coordinates by a scalar..TP.B div3Divide coordinates by a scalar..TP.B eqpt3Test two points for exact equality..TP.B closept3Is the distance between two points smaller than .IR eps ?.TP.B dot3Dot product..TP.B cross3Cross product..TP.B len3Distance to the origin..TP.B dist3Distance between two points..TP.B unit3A unit vector parallel to.IR p ..TP.B midpt3The midpoint of line segment .IR pq ..TP.B lerp3Linear interpolation between .I pand.IR q ..TP.B reflect3The reflection of point.I pin the segment joining .I p0and.IR p1 ..TP.B nearseg3The closest point to .I testpon segment.IR "p0 p1" ..TP.B pldist3The distance from .I pto segment.IR "p0 p1" ..TP.B vdiv3Vector divide \(em the length of the component of .I aparallel to.IR b ,in units of the length of.IR b ..TP.B vrem3Vector remainder \(em the component of .I aperpendicular to.IR b .Ignoring roundoff, we have .BR "eqpt3(add3(mul3(b, vdiv3(a, b)), vrem3(a, b)), a)" ..PD.PPThe following routines convert amongst various representations of pointsand planes.  Planes are represented identically to points, by duality;a point.B pis on a plane.B qwhenever.BR 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.BR p.w=1 ,we can't make the same assumption for planes.The names of these routines are extra-cryptic.  They contain an.B f(for `face') to indicate a plane,.B pfor a point and.B nfor a normal vector.The number.B 2abbreviates the word `to.'The number.B 3reminds us, as before, that we're dealing with affine points.Thus.B pn2f3takes a point and a normal vector and returns the corresponding plane..TF reflect3.TPNameDescription.TP.B pn2f3Compute the plane passing through.I pwith normal.IR n ..TP.B ppp2f3Compute the plane passing through three points..TP.B fff2p3Compute the intersection point of three planes..PD.PPThe names of the following routines end in.B 4because they operate on points in projective 4-space,represented by their homogeneous coordinates..TPpdiv4Perspective division.  Divide.B p.winto.IR p 'scoordinates, converting to affine coordinates.If.B p.wis zero, the result is the same as the argument..TPadd4Add the coordinates of two points..PD.TPsub4Subtract the coordinates of two points..SH SOURCE.B /sys/src/libgeometry.SH "SEE ALSO.IR matrix (2)