aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--geometry.h1
-rw-r--r--quaternion.c2
-rw-r--r--utils.c6
3 files changed, 8 insertions, 1 deletions
diff --git a/geometry.h b/geometry.h
index 7c273d1..3d99b41 100644
--- a/geometry.h
+++ b/geometry.h
@@ -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);
}
diff --git a/utils.c b/utils.c
index 54141e3..9825923 100644
--- a/utils.c
+++ b/utils.c
@@ -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;
+}