aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2020-06-28 14:55:44 +0000
committerrodri <rgl@antares-labs.eu>2020-06-28 14:55:44 +0000
commit88e3ce5e4f8a942a5cf8f74aa295f5cab68d781b (patch)
treee32accc107a8f7d39ed65fac66e3f69043669232
parent78a31caf9c482706040a38173c8e2d6913fa282e (diff)
downloadlibgeometry-88e3ce5e4f8a942a5cf8f74aa295f5cab68d781b.tar.gz
libgeometry-88e3ce5e4f8a942a5cf8f74aa295f5cab68d781b.tar.bz2
libgeometry-88e3ce5e4f8a942a5cf8f74aa295f5cab68d781b.zip
add fclamp.
-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;
+}