diff options
-rw-r--r-- | geometry.h | 1 | ||||
-rw-r--r-- | quaternion.c | 2 | ||||
-rw-r--r-- | utils.c | 6 |
3 files changed, 8 insertions, 1 deletions
@@ -37,6 +37,7 @@ struct Triangle3 { /* utils */ double flerp(double, double, double); +double fclamp(double, double, double); /* Point2 */ Point2 Pt2(double, double, double); diff --git a/quaternion.c b/quaternion.c index 8ef32b8..686c04e 100644 --- a/quaternion.c +++ b/quaternion.c @@ -85,6 +85,6 @@ qrotate(Point3 p, Point3 axis, double θ) θ /= 2; qaxis = Quatvec(cos(θ), mulpt3(axis, sin(θ))); - qr = mulq(mulq(qaxis, Quatvec(0, p)), invq(qaxis)); + qr = mulq(mulq(qaxis, Quatvec(0, p)), invq(qaxis)); /* qpq⁻¹ */ return Pt3(qr.i, qr.j, qr.k, p.w); } @@ -7,3 +7,9 @@ flerp(double a, double b, double t) { return a + (b - a)*t; } + +double +fclamp(double n, double min, double max) +{ + return n < min? min: n > max? max: n; +} |