Laxkit
0.0.7.1
|
Classes | |
class | spacevector |
3 Dimensional vector (x,y,z) More... | |
class | flatvector |
2 Dimensional vector (x,y) More... | |
class | Basis |
Basis with a spacepoint (p) and 3 dimensional axes x,y,z. More... | |
class | spaceline |
3 dimensional line with point p and direction v. More... | |
class | Plane |
Plane with point p and normal n. More... | |
class | flatline |
2 dimensional line with point p and direction v. More... |
Typedefs | |
typedef spacevector | spacepoint |
typedef flatvector | flatpoint |
Functions | |
int | vector_error () |
int | operator== (spacevector v1, spacevector v2) |
nonzero if x==x, y==y and z==z | |
int | operator!= (spacevector v1, spacevector v2) |
nonzero if x!=x || y!=y || z!=z | |
spacevector | operator+ (spacevector a, spacevector b) |
(a,b,c)+(d,e,f)=(a+d, b+e, c+f) | |
spacevector | operator+= (spacevector &a, spacevector b) |
v+=(a,b,c) => (v.x+a, v.y+b, v.z+c) | |
spacevector | operator- (spacevector a, spacevector b) |
(a,b,c)-(d,e,f)=(a-d, b-e, c-f) | |
spacevector | operator-= (spacevector &a, spacevector b) |
v-=(a,b,c) => (v.x-a, v.y-b, v.z-c) | |
spacevector | operator* (double r, spacevector a) |
r*(x,y,z)=(r*x, r*y, r*z) | |
spacevector | operator* (spacevector a, double r) |
(x,y,z)*r=(r*x, r*y, r*z) | |
spacevector | operator*= (spacevector &a, double r) |
v*=r does v=v*r | |
spacevector | operator/ (spacevector a, spacevector b) |
Cross product A x B. | |
spacevector | operator/= (spacevector &a, spacevector &b) |
Cross product, A = A x B. | |
spacevector | operator/ (spacevector a, double r) |
v/r= (v.x/r, v.y/r, v.z/r) | |
spacevector | operator/= (spacevector &v, double r) |
Does v=v/r. | |
double | operator* (spacevector a, spacevector b) |
Dot product (a,b,c)*(d,e,f) = a*d + b*e + c*f. | |
spacevector | operator|| (spacevector a, spacevector b) |
a||b = the part of a that is parallel to b | |
spacevector | operator|= (spacevector a, spacevector b) |
a|=b = the part of a that is perpendicular to b | |
int | isvector (spacevector a) |
Nonzero if any fields of a are nonzero. | |
int | isnotvector (spacevector a) |
Nonzero if all fields of a are zero. | |
int | areparallel (spacevector v1, spacevector v2) |
True (nonzero) if v1 and v2 are parallel. | |
double | norm (spacevector p1) |
The norm of p1=sqrt(p1*p1). | |
double | norm2 (spacevector p1) |
The square of the norm, (p1*p1). | |
int | point_is_in (flatpoint p, flatpoint *points, int n) |
Return the winding number for p in the polyline points. | |
flatvector | transpose (flatvector v) |
(x,y) –> (-y,x) | |
int | operator== (flatvector v1, flatvector v2) |
True if x==x and y==y. | |
int | operator!= (flatvector v1, flatvector v2) |
nonzero if x!=x || y!=y | |
flatvector | operator+ (flatvector a, flatvector b) |
Vector addition. | |
flatvector | operator+= (flatvector &a, flatvector b) |
Vector addition. | |
flatvector | operator- (flatvector a, flatvector b) |
Vector subtraction. | |
flatvector | operator-= (flatvector &a, flatvector b) |
Vector subtraction. | |
flatvector | operator* (double r, flatvector a) |
r*v | |
flatvector | operator* (flatvector a, double r) |
v*r | |
flatvector | operator*= (flatvector &a, double r) |
does v=v*r | |
flatvector | operator/ (flatvector a, double r) |
(x,y)/r=(x/r,y/r) | |
flatvector | operator/= (flatvector &a, double r) |
does v=v/r | |
double | operator* (flatvector a, flatvector b) |
Dot product: a.x*b.x + a.y*b.y. | |
double | distparallel (flatvector a, flatvector b) |
Norm of a parallel to b (which is a*b/norm(b)) | |
flatvector | operator|| (flatvector a, flatvector b) |
Part of a parallel to b (which is a*b/(b*b)*b) | |
flatvector | operator|= (flatvector a, flatvector b) |
Part of a perpendicular to b. | |
int | isnotvector (flatvector v) |
True if any field of v is nonzero. | |
int | areparallel (flatvector v1, flatvector v2) |
True if v1 and v2 parallel. | |
double | norm (flatvector v) |
Norm of v. | |
double | norm2 (flatvector v) |
Square of the norm of v, which is v*v. | |
int | operator== (Basis b1, Basis b2) |
nonzero if p==p, x==x, y==y and z==z | |
double | distance (spacepoint p, spaceline l) |
The distance from point p to line l. | |
double | distance (spacepoint p, Plane pln) |
Distance from point p to plane pln. | |
int | issameplane (Plane p1, Plane p2) |
True (nonzero if p1 and p2 describe the same plane. | |
spacepoint | operator* (spaceline l1, spaceline l2) |
Return the intersection of l1 and l2, without error checking. | |
spacepoint | intersection (spaceline l1, spaceline l2, int &err) |
Return the intersection of l1 and l2, with error checking. | |
spaceline | operator* (Plane p1, Plane p2) |
Return the intersection of p1 and p2, no error checking. | |
spaceline | intersection (Plane p1, Plane p2, int &err) |
Return the intersection of p1 and p2, no error checking. | |
spacepoint | operator* (spaceline l, Plane p) |
The intersection of line l and plane p, no error checking. | |
spacepoint | intersection (spaceline l, Plane pl, int &err) |
The intersection of line l and plane p, with error checking. | |
Plane | operator+ (spaceline l1, spaceline l2) |
Return the plane formed from lines l1 and l2. | |
Plane | linesplane (spaceline l1, spaceline l2, int &err) |
Return the plane formed from the 2 lines. | |
void | normalize (flatvector &v) |
Make v=v/sqrt(v*v). Do nothing if v*v==0. | |
void | normalize (spacevector &v) |
Make v=v/sqrt(v*v). Do nothing if v*v==0. | |
void | normalize (Basis &b) |
Make the axes be a normalized basis (all axes have unit lengths). | |
double | angle (spacevector p1, spacevector p2, int dec) |
Return the angle between p1 and p2. | |
double | angle (flatvector p1, flatvector p2, int dec) |
Return the angle between p1 and p2. Will be in range [0..pi]. | |
double | angle_full (flatvector p1, flatvector p2, int dec) |
double | angle2 (flatvector p1, flatvector p2, int dec) |
Return a signed angle using the asin of the norm of the 3-d cross product of p1 x p2, which will be an all z number. | |
double | distance (spacepoint p1, spacepoint p2) |
Distance between p1 and p2. | |
double | distance (flatpoint p1, flatpoint p2) |
Distance between points p1 and p2. | |
double | distance (flatpoint p, flatline l) |
Distance of point p to line l. | |
double | distance (flatpoint p, flatpoint p1, flatpoint p2) |
Distance of point p to segment between p1 to p2. | |
flatpoint | operator* (flatline l1, flatline l2) |
Return intersection of l1 and l2, no error checking. | |
int | intersection (flatline l1, flatline l2, flatpoint &p) |
Return intersection of l1 and l2, put point in p, return error code. | |
int | intersection (flatline l1, flatline l2, flatpoint *p, double *index1, double *index2) |
Find intersection of l1 and l2, and associated data. | |
double | findindex (flatpoint p, flatline l) |
For a point p on l, p=l.p + t*l.v, finds and returns t. | |
int | segmentandline (flatpoint p1, flatpoint p2, flatline l, flatpoint &p) |
For segment between p1 and p2, find intersection with line l. | |
int | segmentcross (flatpoint a1, flatpoint a2, flatpoint b1, flatpoint b2, flatpoint &p) |
Find the intersection of two segments [a1,a2] and [b1,b2], put answer in p. | |
flatline | flatten (spaceline l3d, Basis bas) |
Flatten the line l3d to be the orthographic projection onto basis x,y. | |
flatpoint | flatten (spacepoint pnt, Basis bas) |
Flatten the point to be the orthographic projection onto basis x,y. | |
flatpoint | rotate (flatpoint p, double ang, int dec) |
Rotate the flatvector p angle ang. | |
flatpoint | rotate (flatpoint p, flatpoint orig, double ang, int dec) |
Rotate p around orig by angle ang. | |
spacepoint | rotate (spacepoint p, spaceline axis, double ang, int dec) |
Rotate p around axis. | |
void | rotate (Basis &b, char w, double ang, int dec) |
Rotate the basis around its 'x', 'y', or 'z' axis. | |
spacevector | rotate (spacevector v, spacevector axis, double ang, int dec) |
Rotate vector v about an axis. | |
void | rotate (Basis &b, spacevector w) |
Rotate the basis about an axis w. | |
void | rotate (Basis &b, spacevector w, double ang) |
Rotate the basis about an axis w, pointing away from b.p. | |
void | transform (flatline &l, Basis b) |
Transform flatline l to coordinates in basis b. | |
void | transform (spaceline &l, Basis b) |
Transform line l to coordinates in basis b. | |
void | transform (spacevector &v, Basis b) |
Transform point v to coordinates in basis b. | |
spacepoint | invert (spacepoint p, spacepoint orig) |
Invert point p through orig: return orig-(p-orig) | |
void | spacevector::normalize () |
Make a unit vector, preserving angle. If null vector, do nothing. | |
spacevector | spacevector::operator- () |
-v => (-v.x, -v.y, -v.z) | |
void | flatvector::normalize () |
Make a unit vector, preserving angle. If null vector, do nothing. | |
flatvector | flatvector::operator- () |
v=-v | |
Basis::Basis (spacepoint pp, spacepoint xx, spacepoint yy, spacepoint zz) | |
Basis::Basis (spacepoint p1, spacepoint p2, spacepoint p3) | |
void | Basis::Set (spacepoint p1, spacepoint p2, spacepoint p3) |
Basis::Basis (double *np, double *nx, double *ny, double *nz) | |
Create the basis from 4 arrays of 3 doubles. | |
spacepoint | Basis::transformTo (spacepoint &v) |
Transform point v to coordinates in basis. | |
spacepoint | Basis::transformFrom (spacepoint &v) |
Transform point v to coordinates from basis. |
Variables | |
static int | vectorop_error = 0 |
This group defines lots of functions and classes that are handy in dealing with 2 and 3 dimensional vectors. Basically, this means adding and subtracting vectors, cross products, dot products, bases, lines, planes, and intersections among these things.
#include <lax/vectors.h>
double angle | ( | spacevector | p1, |
spacevector | p2, | ||
int | dec | ||
) |
Return the angle between p1 and p2.
This pretends that both vectors are in the same plane.
References isnotvector(), and norm().
Referenced by LaxInterfaces::CoordinatePolygon(), LaxInterfaces::PatchInterface::MouseMove(), and Laxkit::transform_to_basics().
double angle2 | ( | flatvector | p1, |
flatvector | p2, | ||
int | dec | ||
) |
Return a signed angle using the asin of the norm of the 3-d cross product of p1 x p2, which will be an all z number.
Return value will be in range [-pi/2..pi/2].
References norm().
Referenced by Laxkit::DoublePanner::Newangle(), Laxkit::DisplayerXlib::Newangle(), and Laxkit::Displayer::Newangle().
double angle_full | ( | flatvector | p1, |
flatvector | p2, | ||
int | dec | ||
) |
Return the angle between p1 and p2. Will be in range [-pi..pi]. If a negative angle, then it is in clockwise direction, else counterclockwise, in a right handed coordinate system.
Basis::Basis | ( | spacepoint | p1, |
spacepoint | p2, | ||
spacepoint | p3 | ||
) |
p=p1, z=p2-p1, x points from p3 perpendicularly away from z
References norm().
Distance of point p to segment between p1 to p2.
If the point is too far off the segment on either end, then it is just the distance to the corresponding segment endpoint.
References distance(), and findindex().
For a point p on l, p=l.p + t*l.v, finds and returns t.
return l.v*(p-l.p)/(l.v*l.v);
This is not really using the point p, but the point on the line where a line extending from p goes through the line perpendicularly.
Referenced by distance(), segmentandline(), and segmentcross().
spacepoint intersection | ( | spaceline | l1, |
spaceline | l2, | ||
int & | err | ||
) |
Return the intersection of l1 and l2, with error checking.
If lines do not intersect, (0,0,0) is returned.
err is 0 if lines interesect, 1 if the lines are nonintersecting and parallel, -1 if the lines are the same line, 2 if the lines are skew (non-parallel, non-interesecting).
Referenced by segmentandline(), and segmentcross().
Return the intersection of p1 and p2, no error checking.
err is 0 if the planes intersect, 1 if planes are parallel and not the same, and -1 if p1 and p2 are the same plane.
spacepoint intersection | ( | spaceline | l, |
Plane | pl, | ||
int & | err | ||
) |
The intersection of line l and plane p, with error checking.
err is 0 for success, -1 for line is in the plane, 1 for line is not in the plane and not intersecting.
Return intersection of l1 and l2, put point in p, return error code.
Returns -1 if the lines are the same line, 1 if they are different but parallel, and 0 if they intersect in a single point.
Find intersection of l1 and l2, and associated data.
Returns -1 if the lines are the same line, 1 if they are different but parallel, and 0 if they intersect in a single point.
The actual intersection point, if any, will be put in p, and is equal to (l1.p+index1*l1.v) and also to (l1.p+index1*l1.v). The indices will be returned when index1 or 2 are not NULL.
If there is an error, p, index1, index2 are not changed.
References distance(), and transpose().
Return the plane formed from the 2 lines.
err is 0 for success, -1 for the lines being the same, and 1 for lines being skew.
void normalize | ( | Basis & | b | ) |
Make the axes be a normalized basis (all axes have unit lengths).
This first normalizes the z axis, then recomputes the x axis to be the part of x perpendicular to z, then y is found as the cross product of z and x. This corrects for any previous skewing of the basis axes.
References normalize().
spacepoint operator* | ( | spaceline | l1, |
spaceline | l2 | ||
) |
Return the intersection of l1 and l2, without error checking.
If lines do not intersect, (0,0,0) is returned.
References distance(), and isnotvector().
Return the plane formed from lines l1 and l2.
If possible, the plane's point is the intersection of the lines. else *** other erorrs***
spacevector operator/ | ( | spacevector | a, |
spacevector | b | ||
) |
Cross product A x B.
Note the amazing math fact that: ||A x B|| = ||A|| ||B|| sin(theta), where theta is the angle between the two. The cross product direction can be determined with the right hand rule. Put you fingers pointing in the a direction. Now curl your fingers in the direction of the b direction, and stick your thumb away from your fingers. Your thumb now points in the direction of A x B.
All this means that you can determine whether an ange is clockwise or counterclockwise by examining the direction of the cross product.
Return the winding number for p in the polyline points.
Automatically closes points.
Referenced by Laxkit::point_is_in_bez().
Rotate the flatvector p angle ang.
This is counterclockwise for possitive ang, looking at standard mathematical basis having positive x to the right, and positive y upward. Would be clockwise for typical computer viewing.
Referenced by LaxInterfaces::EllipseInterface::CharInput(), LaxInterfaces::EllipseInterface::getpoint(), LaxInterfaces::RectInterface::MouseMove(), LaxInterfaces::PatchInterface::MouseMove(), Laxkit::DoublePanner::Newangle(), Laxkit::DisplayerXlib::Newangle(), Laxkit::Displayer::Newangle(), rotate(), and Laxkit::transform_from_basics().
For segment between p1 and p2, find intersection with line l.
Returns 1 if there is an intersection, or 0 if there is not.
References findindex(), and intersection().
Referenced by Laxkit::Displayer::drawrealline().
Find the intersection of two segments [a1,a2] and [b1,b2], put answer in p.
Returns 1 if there is an intersection, or 0 if there is not.
References findindex(), and intersection().
void Basis::Set | ( | spacepoint | p1, |
spacepoint | p2, | ||
spacepoint | p3 | ||
) |
p=p1, z=p2-p1, x points from p3 perpendicularly away from z
References norm().