40#ifndef GEOGRAM_BASIC_GEOMETRY
41#define GEOGRAM_BASIC_GEOMETRY
180 (p1.x + p2.x + p3.x) / 3.0,
181 (p1.y + p2.y + p3.y) / 3.0,
182 (p1.z + p2.z + p3.z) / 3.0
197 (p1.x + p2.x + p3.x) / 3.0,
198 (p1.y + p2.y + p3.y) / 3.0
209 double lab = ::sqrt(length2(a)*length2(b));
210 double result = (lab > 1e-50) ? (
dot(a, b) / lab) : 1.0;
236 double lab = ::sqrt(length2(a)*length2(b));
237 double result = (lab > 1e-20) ? (
dot(a, b) / lab) : 1.0;
252 return a.x * b.y - a.y * b.x;
263 return det(a, b) > 0 ?
277 return cross(p2 - p1, p3 - p1);
298 const double* p1,
const double* p2,
const double* p3
300 double Ux = p2[0] - p1[0];
301 double Uy = p2[1] - p1[1];
302 double Uz = p2[2] - p1[2];
304 double Vx = p3[0] - p1[0];
305 double Vy = p3[1] - p1[1];
306 double Vz = p3[2] - p1[2];
308 double Nx = Uy*Vz - Uz*Vy;
309 double Ny = Uz*Vx - Ux*Vz;
310 double Nz = Ux*Vy - Uy*Vx;
311 return 0.5 * ::sqrt(Nx*Nx+Ny*Ny+Nz*Nz);
334 const double* p1,
const double* p2,
const double* p3
336 double a = p2[0]-p1[0];
337 double b = p3[0]-p1[0];
338 double c = p2[1]-p1[1];
339 double d = p3[1]-p1[1];
340 return 0.5*(a*d-b*c);
354 return 0.5 *
det(p2 - p1, p3 - p1);
378 const double* p1,
const double* p2,
const double* p3
438 return dot(p2 - p1, cross(p3 - p1, p4 - p1)) / 6.0;
451 const double* p1,
const double* p2,
452 const double* p3,
const double* p4
455 *
reinterpret_cast<const vec3*
>(p1),
456 *
reinterpret_cast<const vec3*
>(p2),
457 *
reinterpret_cast<const vec3*
>(p3),
458 *
reinterpret_cast<const vec3*
>(p4)
507 double a,
double b,
double c,
510 double abc = a + b + c;
512 V = area / 3.0 * abc;
516 double s = area / 12.0;
517 Vg.x = s * (wp * p.x + wq * q.x + wr * r.x);
518 Vg.y = s * (wp * p.y + wq * q.y + wr * r.y);
519 Vg.z = s * (wp * p.z + wq * q.z + wr * r.z);
536 double a,
double b,
double c
539 sqrt(::fabs(a)) + sqrt(::fabs(b)) + sqrt(::fabs(c))
564 double u = 1.0 - s - t;
566 u * p1.x + s * p2.x + t * p3.x,
567 u * p1.y + s * p2.y + t * p3.y,
568 u * p1.z + s * p2.z + t * p3.z
587 vec3 n = cross(p2 - p1, p3 - p1);
591 d = -(a * p1.x + b * p1.y + c * p1.z);
604 d = -(a * p.x + b * p.y + c * p.z);
611 double a_in,
double b_in,
double c_in,
double d_in
629 return vec3(a, b, c);
652 if(b[c] < xyz_min[c]) {
655 if(b[c] > xyz_max[c]) {
674 if(B1.xyz_max[c] < B2.xyz_min[c]) {
677 if(B1.xyz_min[c] > B2.xyz_max[c]) {
693 target.xyz_min[c] = std::min(B1.xyz_min[c], B2.xyz_min[c]);
694 target.xyz_max[c] = std::max(B1.xyz_max[c], B2.xyz_max[c]);
715 if(b[c] < xy_min[c]) {
718 if(b[c] > xy_max[c]) {
736 if(B1.xy_max[c] < B2.xy_min[c]) {
739 if(B1.xy_min[c] > B2.xy_max[c]) {
755 target.xy_min[c] = std::min(B1.xy_min[c], B2.xy_min[c]);
756 target.xy_max[c] = std::max(B1.xy_max[c], B2.xy_max[c]);
787 result[i] += v[j] * m(j,i) ;
792 result[0], result[1], result[2]
823 result[i] += v[j] * m(j,i) ;
829 result[0] / result[3],
830 result[1] / result[3],
831 result[2] / result[3]
850 FT res[4] = {FT(0), FT(0), FT(0), FT(0)};
854 res[i] += v[j] * m(j,i) ;
858 return vecng<4,FT>(res[0], res[1], res[2], res[3]) ;
Common include file, providing basic definitions. Should be included before anything else by all head...
Axis-aligned bounding box.
bool contains(const vec2 &b) const
Tests whether a box contains a point.
Axis-aligned bounding box.
bool contains(const vec3 &b) const
Tests whether a box contains a point.
void load_identity()
Sets the matrix to identity.
T * data()
Gets modifiable vector data.
double det(const vec2 &a, const vec2 &b)
Computes the determinant of two vectors.
double triangle_signed_area(const vec2 &p1, const vec2 &p2, const vec2 &p3)
Computes the area of a 2d triangle.
vec3 tetra_circum_center(const vec3 &p1, const vec3 &p2, const vec3 &p3, const vec3 &p4)
Computes the center of the circumscribed sphere of 3d tetrahedron.
vec3 random_point_in_triangle(const vec3 &p1, const vec3 &p2, const vec3 &p3)
Generates a random point in a 3d triangle.
double tetra_volume(const vec3 &p1, const vec3 &p2, const vec3 &p3, const vec3 &p4)
Computes the volume of a 3d tetrahedron.
vec3 perpendicular(const vec3 &V)
Computes a 3d vector orthogonal to another one.
vec3 triangle_normal(const vec3 &p1, const vec3 &p2, const vec3 &p3)
Computes the normal of a 3d triangle.
double triangle_mass(const vec3 &p, const vec3 &q, const vec3 &r, double a, double b, double c)
Computes the mass of a 3d triangle with weighted points.
double cos_angle(const vec3 &a, const vec3 &b)
Computes the cosine of the angle between two 3d vectors.
double triangle_area(const vec3 &p1, const vec3 &p2, const vec3 &p3)
Computes the area of a 3d triangle.
double triangle_signed_area_2d(const double *p1, const double *p2, const double *p3)
Computes the area of a 2d triangle.
void triangle_centroid(const vec3 &p, const vec3 &q, const vec3 &r, double a, double b, double c, vec3 &Vg, double &V)
Computes the centroid of a 3d triangle with weighted points.
bool has_nan(const vec3 &v)
Tests whether a 3d vector has a NaN (not a number) coordinate.
double triangle_area_2d(const double *p1, const double *p2, const double *p3)
Computes the area of a 2d triangle.
double angle(const vec3 &a, const vec3 &b)
Computes the angle between two 3d vectors.
double triangle_area_3d(const double *p1, const double *p2, const double *p3)
Computes the area of a 3d triangle.
double tetra_signed_volume(const vec3 &p1, const vec3 &p2, const vec3 &p3, const vec3 &p4)
Computes the signed volume of a 3d tetrahedron.
coord_index_t triangle_normal_axis(const vec3 &p1, const vec3 &p2, const vec3 &p3)
Gets the axis that is most normal to a triangle.
vec3 barycenter(const vec3 &p1, const vec3 &p2)
Computes the barycenter of two points in 3d.
vec2 triangle_circumcenter(const vec2 &p1, const vec2 &p2, const vec2 &p3)
Computes the center of the circumscribed circle of a 2d triangle.
float64 random_float64()
Returns a 64 bits float between 0 and 1.
bool is_nan(float32 x)
Checks whether a 32 bits float is "not a number".
Global Vorpaline namespace.
Matrix< 4, Numeric::float64 > mat4
Represents a 4x4 matrix.
bool bboxes_overlap(const Box &B1, const Box &B2)
Tests whether two Boxes have a non-empty intersection.
vecng< 3, Numeric::float32 > vec3f
Represents points and vectors in 3d with single-precision coordinates.
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors. vecng
vecng< 4, Numeric::float32 > vec4f
Represents points and vectors in 4d with single-precision coordinates.
void bbox_union(Box &target, const Box &B1, const Box &B2)
Computes the smallest Box that encloses two Boxes.
vecng< 3, FT > transform_vector(const vecng< 3, FT > &v, const Matrix< 4, FT > &m)
Applies a 3d transform to a 3d vector.
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
vecng< 3, Numeric::int32 > vec3i
Represents points and vectors in 3d with integer coordinates.
void geo_clamp(T &x, T min, T max)
Clamps a value to a range.
mat4 create_scaling_matrix(double s)
Creates a scaling matrix.
vecng< 3, FT > transform_point(const vecng< 3, FT > &v, const Matrix< 4, FT > &m)
Applies a 3d transform to a 3d point.
geo_index_t index_t
The type for storing and manipulating indices.
vecng< 4, Numeric::float64 > vec4
Represents points and vectors in 4d.
mat4 create_translation_matrix(const vec3 &T)
Creates a translation matrix from a vector.
vecng< 2, Numeric::int32 > vec2i
Represents points and vectors in 2d with integer coordinates.
Matrix< 3, Numeric::float64 > mat3
Represents a 3x3 matrix.
vecng< 2, Numeric::float32 > vec2f
Represents points and vectors in 2d with single-precision coordinates.
vecng< 2, Numeric::float64 > vec2
Represents points and vectors in 2d.
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.
vecng< 4, Numeric::int32 > vec4i
Represents points and vectors in 4d with integer coordinates.
Matrix< 2, Numeric::float64 > mat2
Represents a 2x2 matrix.
Plane(const vec3 &p1, const vec3 &p2, const vec3 &p3)
Constructs the plane passing through three points.
Plane(const vec3 &p, const vec3 &n)
Constructs a plane passign through a point and orthogonal to a vector.
Plane(double a_in, double b_in, double c_in, double d_in)
Constructs a plane from the coefficients of its equation.
Plane()
Constructs an uninitialized plane.
vec3 normal() const
Gets the normal vector of the plane.
A Ray, in parametric form.
Ray(vec3 O, vec3 D)
Ray constructor.