2011-03-30 13:47:56 +00:00
|
|
|
#pragma lib "libgeometry.a"
|
|
|
|
#pragma src "/sys/src/libgeometry"
|
2023-01-29 23:11:05 +00:00
|
|
|
|
|
|
|
#define DEG 0.01745329251994330 /* π/180 */
|
|
|
|
|
|
|
|
typedef struct Point2 Point2;
|
2011-03-30 13:47:56 +00:00
|
|
|
typedef struct Point3 Point3;
|
2023-01-29 23:11:05 +00:00
|
|
|
typedef double Matrix[3][3];
|
|
|
|
typedef double Matrix3[4][4];
|
2011-03-30 13:47:56 +00:00
|
|
|
typedef struct Quaternion Quaternion;
|
2023-01-29 23:11:05 +00:00
|
|
|
typedef struct RFrame RFrame;
|
|
|
|
typedef struct RFrame3 RFrame3;
|
|
|
|
typedef struct Triangle2 Triangle2;
|
|
|
|
typedef struct Triangle3 Triangle3;
|
|
|
|
|
|
|
|
struct Point2 {
|
|
|
|
double x, y, w;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Point3 {
|
2011-03-30 13:47:56 +00:00
|
|
|
double x, y, z, w;
|
|
|
|
};
|
2023-01-29 23:11:05 +00:00
|
|
|
|
|
|
|
struct Quaternion {
|
2011-03-30 13:47:56 +00:00
|
|
|
double r, i, j, k;
|
|
|
|
};
|
2023-01-29 23:11:05 +00:00
|
|
|
|
|
|
|
struct RFrame {
|
|
|
|
Point2 p;
|
|
|
|
Point2 bx, by;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RFrame3 {
|
|
|
|
Point3 p;
|
|
|
|
Point3 bx, by, bz;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Triangle2
|
|
|
|
{
|
|
|
|
Point2 p0, p1, p2;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Triangle3 {
|
|
|
|
Point3 p0, p1, p2;
|
2011-03-30 13:47:56 +00:00
|
|
|
};
|
2023-01-29 23:11:05 +00:00
|
|
|
|
|
|
|
/* utils */
|
|
|
|
double flerp(double, double, double);
|
2024-03-21 11:38:02 +00:00
|
|
|
double fberp(double, double, double, Point3);
|
2023-01-29 23:11:05 +00:00
|
|
|
double fclamp(double, double, double);
|
|
|
|
|
|
|
|
/* Point2 */
|
|
|
|
Point2 Pt2(double, double, double);
|
|
|
|
Point2 Vec2(double, double);
|
|
|
|
Point2 addpt2(Point2, Point2);
|
|
|
|
Point2 subpt2(Point2, Point2);
|
|
|
|
Point2 mulpt2(Point2, double);
|
|
|
|
Point2 divpt2(Point2, double);
|
|
|
|
Point2 lerp2(Point2, Point2, double);
|
2024-03-21 11:38:02 +00:00
|
|
|
Point2 berp2(Point2, Point2, Point2, Point3);
|
2023-01-29 23:11:05 +00:00
|
|
|
double dotvec2(Point2, Point2);
|
|
|
|
double vec2len(Point2);
|
|
|
|
Point2 normvec2(Point2);
|
|
|
|
int edgeptcmp(Point2, Point2, Point2);
|
|
|
|
int ptinpoly(Point2, Point2*, ulong);
|
|
|
|
|
|
|
|
/* Point3 */
|
|
|
|
Point3 Pt3(double, double, double, double);
|
|
|
|
Point3 Vec3(double, double, double);
|
|
|
|
Point3 addpt3(Point3, Point3);
|
|
|
|
Point3 subpt3(Point3, Point3);
|
|
|
|
Point3 mulpt3(Point3, double);
|
|
|
|
Point3 divpt3(Point3, double);
|
|
|
|
Point3 lerp3(Point3, Point3, double);
|
2024-03-21 11:38:02 +00:00
|
|
|
Point3 berp3(Point3, Point3, Point3, Point3);
|
2023-01-29 23:11:05 +00:00
|
|
|
double dotvec3(Point3, Point3);
|
|
|
|
Point3 crossvec3(Point3, Point3);
|
|
|
|
double vec3len(Point3);
|
|
|
|
Point3 normvec3(Point3);
|
2024-08-19 21:30:14 +00:00
|
|
|
int lineXsphere(Point3*, Point3, Point3, Point3, double, int);
|
2024-10-14 12:04:35 +00:00
|
|
|
int ptincylinder(Point3, Point3, Point3, double);
|
|
|
|
int ptincone(Point3, Point3, Point3, double);
|
2023-01-29 23:11:05 +00:00
|
|
|
|
|
|
|
/* Matrix */
|
|
|
|
void identity(Matrix);
|
|
|
|
void addm(Matrix, Matrix);
|
|
|
|
void subm(Matrix, Matrix);
|
|
|
|
void mulm(Matrix, Matrix);
|
|
|
|
void smulm(Matrix, double);
|
|
|
|
void transposem(Matrix);
|
|
|
|
double detm(Matrix);
|
|
|
|
double tracem(Matrix);
|
2023-12-20 11:27:36 +00:00
|
|
|
double minorm(Matrix, int, int);
|
|
|
|
double cofactorm(Matrix, int, int);
|
2023-01-29 23:11:05 +00:00
|
|
|
void adjm(Matrix);
|
|
|
|
void invm(Matrix);
|
|
|
|
Point2 xform(Point2, Matrix);
|
|
|
|
|
|
|
|
/* Matrix3 */
|
|
|
|
void identity3(Matrix3);
|
|
|
|
void addm3(Matrix3, Matrix3);
|
|
|
|
void subm3(Matrix3, Matrix3);
|
|
|
|
void mulm3(Matrix3, Matrix3);
|
|
|
|
void smulm3(Matrix3, double);
|
|
|
|
void transposem3(Matrix3);
|
|
|
|
double detm3(Matrix3);
|
|
|
|
double tracem3(Matrix3);
|
2023-12-20 11:27:36 +00:00
|
|
|
double minorm3(Matrix3, int, int);
|
|
|
|
double cofactorm3(Matrix3, int, int);
|
2023-01-29 23:11:05 +00:00
|
|
|
void adjm3(Matrix3);
|
|
|
|
void invm3(Matrix3);
|
|
|
|
Point3 xform3(Point3, Matrix3);
|
|
|
|
|
|
|
|
/* Quaternion */
|
|
|
|
Quaternion Quat(double, double, double, double);
|
|
|
|
Quaternion Quatvec(double, Point3);
|
|
|
|
Quaternion addq(Quaternion, Quaternion);
|
|
|
|
Quaternion subq(Quaternion, Quaternion);
|
|
|
|
Quaternion mulq(Quaternion, Quaternion);
|
|
|
|
Quaternion smulq(Quaternion, double);
|
|
|
|
Quaternion sdivq(Quaternion, double);
|
|
|
|
double dotq(Quaternion, Quaternion);
|
|
|
|
Quaternion invq(Quaternion);
|
2011-03-30 13:47:56 +00:00
|
|
|
double qlen(Quaternion);
|
2023-01-29 23:11:05 +00:00
|
|
|
Quaternion normq(Quaternion);
|
2011-03-30 13:47:56 +00:00
|
|
|
Quaternion slerp(Quaternion, Quaternion, double);
|
2024-10-14 11:14:50 +00:00
|
|
|
Quaternion qsandwich(Quaternion, Quaternion);
|
|
|
|
Point3 qsandwichpt3(Quaternion, Point3);
|
2023-01-29 23:11:05 +00:00
|
|
|
Point3 qrotate(Point3, Point3, double);
|
|
|
|
|
|
|
|
/* RFrame */
|
2024-05-30 21:11:33 +00:00
|
|
|
void rframematrix(Matrix, RFrame);
|
|
|
|
void rframematrix3(Matrix3, RFrame3);
|
2023-01-29 23:11:05 +00:00
|
|
|
Point2 rframexform(Point2, RFrame);
|
|
|
|
Point3 rframexform3(Point3, RFrame3);
|
|
|
|
Point2 invrframexform(Point2, RFrame);
|
|
|
|
Point3 invrframexform3(Point3, RFrame3);
|
|
|
|
|
|
|
|
/* Triangle2 */
|
|
|
|
Point2 centroid(Triangle2);
|
|
|
|
Point3 barycoords(Triangle2, Point2);
|
|
|
|
|
|
|
|
/* Triangle3 */
|
|
|
|
Point3 centroid3(Triangle3);
|
|
|
|
|
|
|
|
/* Fmt */
|
|
|
|
#pragma varargck type "v" Point2
|
|
|
|
#pragma varargck type "V" Point3
|
|
|
|
int vfmt(Fmt*);
|
|
|
|
int Vfmt(Fmt*);
|
|
|
|
void GEOMfmtinstall(void);
|