1#ifndef MECACELL_GEOMETRY_H
2#define MECACELL_GEOMETRY_H
4#include "../utilities/utils.hpp"
20 const Vec &o,
const Vec &r,
21 const double tolerance = 0) {
32 double a = 1.0 - l - b;
33 return {0 - tolerance <= a && a <= 1.0 + tolerance && 0 - tolerance <= b &&
34 b <= 1.0 + tolerance && 0 - tolerance <= l && l <= 1.0 + tolerance,
35 a * v0 + b * v1 + l * v2};
54 const Vec &v2,
const Vec &p,
55 const double tolerance = 0) {
63 double a = 1.0 - l - b;
64 return {0 - tolerance <= a && a <= 1.0 + tolerance && 0 - tolerance <= b &&
65 b <= 1.0 + tolerance && 0 - tolerance <= l && l <= 1.0 + tolerance,
66 a * v0 + b * v1 + l * v2};
88 double sqV0pa = v0p.
dot(a);
89 double sqV0pb = v0p.
dot(b);
90 double sqV1pc = v1p.
dot(c);
91 double adist, bdist, cdist;
92 double v0dist, v1dist, v2dist;
96 if (sqV0pa >= 0 && sqV0pa <= a.
sqlength()) {
97 adist = ((v0 + (sqV0pa / a.
sqlength()) * a) - p).sqlength();
98 }
else if (sqV0pa < 0) {
103 if (sqV0pb >= 0 && sqV0pb <= b.
sqlength()) {
104 bdist = ((v0 + (sqV0pb / b.
sqlength()) * b) - p).sqlength();
105 }
else if (sqV0pb < 0) {
110 if (sqV1pc >= 0 && sqV1pc <= c.
sqlength()) {
111 cdist = ((v1 + (sqV1pc / c.
sqlength()) * c) - p).sqlength();
112 }
else if (sqV1pc < 0) {
117 return sqrt(min(adist, min(bdist, cdist)));
general purpose 3D vector/point class.
double sqlength() const
compute the square length of the current vector (faster than length)
static double rayCast(const Vector3D &o, const Vector3D &n, const Vector3D &p, const Vector3D &r)
simple raycasting on a plane
const Vector3D cross(const Vector3D &v) const
cross product calculation
double dot(const Vector3D &v) const
dot product calculation
this file contains various miscellanious utility functions & helpers *
std::pair< bool, Vec > rayInTriangle(const Vec &v0, const Vec &v1, const Vec &v2, const Vec &o, const Vec &r, const double tolerance=0)
test if a ray hits a triangle
std::pair< bool, Vec > projectionIntriangle(const Vec &v0, const Vec &v1, const Vec &v2, const Vec &p, const double tolerance=0)
tests if the projection of a point along the normal of a triangle is inside said triangle
double closestDistToTriangleEdge(const Vec &v0, const Vec &v1, const Vec &v2, const Vec &p)
computes the smallest distance to a triangle edge from a given point
double sqrt(double x)
Computes the square root of a number.