started on the fracture code
[meshfrac] / src / geom.c
diff --git a/src/geom.c b/src/geom.c
new file mode 100644 (file)
index 0000000..f7e1740
--- /dev/null
@@ -0,0 +1,23 @@
+#include "geom.h"
+
+float plane_dist(const struct plane *p, const cgm_vec3 *pt)
+{
+       return fabs(plane_sdist(p, pt));
+}
+
+float plane_sdist(const struct plane *p, const cgm_vec3 *pt)
+{
+       cgm_vec3 v = p->pt;
+       cgm_vsub(&v, pt);
+       return cgm_vdot(&v, &p->norm);
+}
+
+void midplane(struct plane *p, const cgm_vec3 *a, const cgm_vec3 *b)
+{
+       p->norm = *b;
+       cgm_vsub(&p->norm, a);
+       cgm_vnormalize(&p->norm);
+       p->pt.x = a->x + p->norm.x * 0.5f;
+       p->pt.y = a->y + p->norm.y * 0.5f;
+       p->pt.z = a->z + p->norm.z * 0.5f;
+}