Geogram Version 1.10.2
A programming library of geometric algorithms
Loading...
Searching...
No Matches
geometry.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef GEOGRAM_BASIC_GEOMETRY
41#define GEOGRAM_BASIC_GEOMETRY
42
45
50
51namespace GEO {
52
53 /************************************************************************/
54
60
66
72
79
86
93
94
101
108
115
122
129
136
142
148
154
155 /************************************************************************/
156
162 inline double det(const mat2& M) {
163 return det2x2(
164 M(0,0), M(0,1),
165 M(1,0), M(1,1)
166 );
167 }
168
174 inline double det(const mat3& M) {
175 return det3x3(
176 M(0,0), M(0,1), M(0,2),
177 M(1,0), M(1,1), M(1,2),
178 M(2,0), M(2,1), M(2,2)
179 );
180 }
181
187 inline double det(const mat4& M) {
188 return det4x4(
189 M(0,0), M(0,1), M(0,2), M(0,3),
190 M(1,0), M(1,1), M(1,2), M(1,3),
191 M(2,0), M(2,1), M(2,2), M(2,3),
192 M(3,0), M(3,1), M(3,2), M(3,3)
193 );
194 }
195
196 /************************************************************************/
197
201 namespace Geom {
202
209 inline vec3 barycenter(const vec3& p1, const vec3& p2) {
210 return vec3(
211 0.5 * (p1.x + p2.x),
212 0.5 * (p1.y + p2.y),
213 0.5 * (p1.z + p2.z)
214 );
215 }
216
223 inline vec2 barycenter(const vec2& p1, const vec2& p2) {
224 return vec2(
225 0.5 * (p1.x + p2.x),
226 0.5 * (p1.y + p2.y)
227 );
228 }
229
238 const vec3& p1, const vec3& p2, const vec3& p3
239 ) {
240 return vec3(
241 (p1.x + p2.x + p3.x) / 3.0,
242 (p1.y + p2.y + p3.y) / 3.0,
243 (p1.z + p2.z + p3.z) / 3.0
244 );
245 }
246
255 const vec2& p1, const vec2& p2, const vec2& p3
256 ) {
257 return vec2(
258 (p1.x + p2.x + p3.x) / 3.0,
259 (p1.y + p2.y + p3.y) / 3.0
260 );
261 }
262
269 inline double cos_angle(const vec3& a, const vec3& b) {
270 double lab = ::sqrt(length2(a)*length2(b));
271 double result = (lab > 1e-50) ? (dot(a, b) / lab) : 1.0;
272 // Numerical precision problem may occur, and generate
273 // normalized dot products that are outside the valid
274 // range of acos.
275 geo_clamp(result, -1.0, 1.0);
276 return result;
277 }
278
286 inline double angle(const vec3& a, const vec3& b) {
287 return ::acos(cos_angle(a, b));
288 }
289
296 inline double cos_angle(const vec2& a, const vec2& b) {
297 double lab = ::sqrt(length2(a)*length2(b));
298 double result = (lab > 1e-20) ? (dot(a, b) / lab) : 1.0;
299 // Numerical precision problem may occur, and generate
300 // normalized dot products that are outside the valid
301 // range of acos.
302 geo_clamp(result, -1.0, 1.0);
303 return result;
304 }
305
312 inline double det(const vec2& a, const vec2& b) {
313 return a.x * b.y - a.y * b.x;
314 }
315
323 inline double angle(const vec2& a, const vec2& b) {
324 return det(a, b) > 0 ?
325 ::acos(cos_angle(a, b)) :
326 -::acos(cos_angle(a, b));
327 }
328
336 const vec3& p1, const vec3& p2, const vec3& p3
337 ) {
338 return cross(p2 - p1, p3 - p1);
339 }
340
346 inline double triangle_area_3d(
347 const double* p1, const double* p2, const double* p3
348 ) {
349 double Ux = p2[0] - p1[0];
350 double Uy = p2[1] - p1[1];
351 double Uz = p2[2] - p1[2];
352
353 double Vx = p3[0] - p1[0];
354 double Vy = p3[1] - p1[1];
355 double Vz = p3[2] - p1[2];
356
357 double Nx = Uy*Vz - Uz*Vy;
358 double Ny = Uz*Vx - Ux*Vz;
359 double Nz = Ux*Vy - Uy*Vx;
360 return 0.5 * ::sqrt(Nx*Nx+Ny*Ny+Nz*Nz);
361 }
362
368 inline double triangle_area(
369 const vec3& p1, const vec3& p2, const vec3& p3
370 ) {
371 return triangle_area_3d(p1.data(), p2.data(), p3.data());
372 }
373
383 const double* p1, const double* p2, const double* p3
384 ) {
385 double a = p2[0]-p1[0];
386 double b = p3[0]-p1[0];
387 double c = p2[1]-p1[1];
388 double d = p3[1]-p1[1];
389 return 0.5*(a*d-b*c);
390 }
391
400 inline double triangle_signed_area(
401 const vec2& p1, const vec2& p2, const vec2& p3
402 ) {
403 return 0.5 * det(p2 - p1, p3 - p1);
404 }
405
413 inline double triangle_area(
414 const vec2& p1, const vec2& p2, const vec2& p3
415 ) {
416 return ::fabs(triangle_signed_area(p1, p2, p3));
417 }
418
426 inline double triangle_area_2d(
427 const double* p1, const double* p2, const double* p3
428 ) {
429 return ::fabs(triangle_signed_area_2d(p1,p2,p3));
430 }
431
441 const vec2& p1, const vec2& p2, const vec2& p3
442 );
443
449 inline bool has_nan(const vec3& v) {
450 return
451 Numeric::is_nan(v.x) ||
452 Numeric::is_nan(v.y) ||
453 Numeric::is_nan(v.z);
454 }
455
461 inline bool has_nan(const vec2& v) {
462 return
463 Numeric::is_nan(v.x) ||
464 Numeric::is_nan(v.y);
465 }
466
472 vec3 GEOGRAM_API perpendicular(const vec3& V);
473
483 inline double tetra_signed_volume(
484 const vec3& p1, const vec3& p2,
485 const vec3& p3, const vec3& p4
486 ) {
487 return dot(p2 - p1, cross(p3 - p1, p4 - p1)) / 6.0;
488 }
489
499 inline double tetra_signed_volume(
500 const double* p1, const double* p2,
501 const double* p3, const double* p4
502 ) {
503 return tetra_signed_volume(
504 *reinterpret_cast<const vec3*>(p1),
505 *reinterpret_cast<const vec3*>(p2),
506 *reinterpret_cast<const vec3*>(p3),
507 *reinterpret_cast<const vec3*>(p4)
508 );
509 }
510
520 inline double tetra_volume(
521 const vec3& p1, const vec3& p2,
522 const vec3& p3, const vec3& p4
523 ) {
524 return ::fabs(tetra_signed_volume(p1, p2, p3, p4));
525 }
526
538 const vec3& p1, const vec3& p2,
539 const vec3& p3, const vec3& p4
540 );
541
554 inline void triangle_centroid(
555 const vec3& p, const vec3& q, const vec3& r,
556 double a, double b, double c,
557 vec3& Vg, double& V
558 ) {
559 double abc = a + b + c;
560 double area = Geom::triangle_area(p, q, r);
561 V = area / 3.0 * abc;
562 double wp = a + abc;
563 double wq = b + abc;
564 double wr = c + abc;
565 double s = area / 12.0;
566 Vg.x = s * (wp * p.x + wq * q.x + wr * r.x);
567 Vg.y = s * (wp * p.y + wq * q.y + wr * r.y);
568 Vg.z = s * (wp * p.z + wq * q.z + wr * r.z);
569 }
570
583 inline double triangle_mass(
584 const vec3& p, const vec3& q, const vec3& r,
585 double a, double b, double c
586 ) {
587 return Geom::triangle_area(p, q, r) / 3.0 * (
588 sqrt(::fabs(a)) + sqrt(::fabs(b)) + sqrt(::fabs(c))
589 );
590 }
591
603 const vec3& p1,
604 const vec3& p2,
605 const vec3& p3
606 ) {
607 double s = Numeric::random_float64();
608 double t = Numeric::random_float64();
609 if(s + t > 1) {
610 s = 1.0 - s;
611 t = 1.0 - t;
612 }
613 double u = 1.0 - s - t;
614 return vec3(
615 u * p1.x + s * p2.x + t * p3.x,
616 u * p1.y + s * p2.y + t * p3.y,
617 u * p1.z + s * p2.z + t * p3.z
618 );
619 }
620 }
621
627 struct Plane {
628
635 Plane(const vec3& p1, const vec3& p2, const vec3& p3) {
636 vec3 n = cross(p2 - p1, p3 - p1);
637 a = n.x;
638 b = n.y;
639 c = n.z;
640 d = -(a * p1.x + b * p1.y + c * p1.z);
641 }
642
649 Plane(const vec3& p, const vec3& n) {
650 a = n.x;
651 b = n.y;
652 c = n.z;
653 d = -(a * p.x + b * p.y + c * p.z);
654 }
655
660 double a_in, double b_in, double c_in, double d_in
661 ) :
662 a(a_in),
663 b(b_in),
664 c(c_in),
665 d(d_in) {
666 }
667
672 }
673
677 vec3 normal() const {
678 return vec3(a, b, c);
679 }
680
681 double a, b, c, d;
682 };
683
684 /*******************************************************************/
685
689 class Box {
690 public:
691 double xyz_min[3];
692 double xyz_max[3];
693
699 Box() {
700 }
701
707 Box(double x1, double y1, double z1, double x2, double y2, double z2) {
708 xyz_min[0] = x1;
709 xyz_min[1] = y1;
710 xyz_min[2] = z1;
711 xyz_max[0] = x2;
712 xyz_max[1] = y2;
713 xyz_max[2] = z2;
714 }
715
721 Box(const vec3& lo, const vec3& hi) {
722 xyz_min[0] = lo.x;
723 xyz_min[1] = lo.y;
724 xyz_min[2] = lo.z;
725 xyz_max[0] = hi.x;
726 xyz_max[1] = hi.y;
727 xyz_max[2] = hi.z;
728 }
729
734 vec3 lo() const {
735 return vec3(xyz_min);
736 }
737
742 vec3 hi() const {
743 return vec3(xyz_max);
744 }
745
751 bool contains(const vec3& b) const {
752 for(coord_index_t c = 0; c < 3; ++c) {
753 if(b[c] < xyz_min[c]) {
754 return false;
755 }
756 if(b[c] > xyz_max[c]) {
757 return false;
758 }
759 }
760 return true;
761 }
762
768 void enlarge(double d) {
769 xyz_min[0] -= d;
770 xyz_min[1] -= d;
771 xyz_min[2] -= d;
772 xyz_max[0] += d;
773 xyz_max[1] += d;
774 xyz_max[2] += d;
775 }
776
783 void clear() {
784 for(index_t c=0; c<3; ++c) {
785 xyz_min[c] = Numeric::max_float64();
786 xyz_max[c] = -Numeric::max_float64();
787 }
788 }
789
796 void add(const vec3& p) {
797 for(index_t c=0; c<3; ++c) {
798 xyz_min[c] = std::min(xyz_min[c], p[c]);
799 xyz_max[c] = std::max(xyz_max[c], p[c]);
800 }
801 }
802
803 };
804
805 typedef Box Box3d;
806
814 inline bool bboxes_overlap(const Box& B1, const Box& B2) {
815 for(coord_index_t c = 0; c < 3; ++c) {
816 if(B1.xyz_max[c] < B2.xyz_min[c]) {
817 return false;
818 }
819 if(B1.xyz_min[c] > B2.xyz_max[c]) {
820 return false;
821 }
822 }
823 return true;
824 }
825
833 inline void bbox_union(Box& target, const Box& B1, const Box& B2) {
834 for(coord_index_t c = 0; c < 3; ++c) {
835 target.xyz_min[c] = std::min(B1.xyz_min[c], B2.xyz_min[c]);
836 target.xyz_max[c] = std::max(B1.xyz_max[c], B2.xyz_max[c]);
837 }
838 }
839
840 /*******************************************************************/
841
845 class Box2d {
846 public:
847 double xy_min[2];
848 double xy_max[2];
849
856 }
857
863 Box2d(double x1, double y1, double x2, double y2) {
864 xy_min[0] = x1;
865 xy_min[1] = y1;
866 xy_max[0] = x2;
867 xy_max[1] = y2;
868 }
869
875 Box2d(const vec2& lo, const vec2& hi) {
876 xy_min[0] = lo.x;
877 xy_min[1] = lo.y;
878 xy_max[0] = hi.x;
879 xy_max[1] = hi.y;
880 }
881
886 vec2 lo() const {
887 return vec2(xy_min);
888 }
889
894 vec2 hi() const {
895 return vec2(xy_max);
896 }
897
903 bool contains(const vec2& b) const {
904 for(coord_index_t c = 0; c < 2; ++c) {
905 if(b[c] < xy_min[c]) {
906 return false;
907 }
908 if(b[c] > xy_max[c]) {
909 return false;
910 }
911 }
912 return true;
913 }
914
920 void enlarge(double d) {
921 xy_min[0] -= d;
922 xy_min[1] -= d;
923 xy_max[0] += d;
924 xy_max[1] += d;
925 }
926
933 void clear() {
934 for(index_t c=0; c<2; ++c) {
935 xy_min[c] = Numeric::max_float64();
936 xy_max[c] = -Numeric::max_float64();
937 }
938 }
939
946 void add(const vec2& p) {
947 for(index_t c=0; c<2; ++c) {
948 xy_min[c] = std::min(xy_min[c], p[c]);
949 xy_max[c] = std::max(xy_max[c], p[c]);
950 }
951 }
952 };
953
954
962 inline bool bboxes_overlap(const Box2d& B1, const Box2d& B2) {
963 for(coord_index_t c = 0; c < 2; ++c) {
964 if(B1.xy_max[c] < B2.xy_min[c]) {
965 return false;
966 }
967 if(B1.xy_min[c] > B2.xy_max[c]) {
968 return false;
969 }
970 }
971 return true;
972 }
973
981 inline void bbox_union(Box2d& target, const Box2d& B1, const Box2d& B2) {
982 for(coord_index_t c = 0; c < 2; ++c) {
983 target.xy_min[c] = std::min(B1.xy_min[c], B2.xy_min[c]);
984 target.xy_max[c] = std::max(B1.xy_max[c], B2.xy_max[c]);
985 }
986 }
987
988 /*******************************************************************/
989
990#ifndef GOMGEN
991
1005 template <class FT> [[deprecated("use operators and vec3/4 conversions")]]
1007 const vecng<3,FT>& v, const Matrix<4,FT>& M
1008 ) {
1009 return vecng<3,FT>( vecng<4,FT>(v,FT(0.0)) * M );
1010 }
1011
1027 template <class FT> [[deprecated("use operators and vec3/4 conversions")]]
1029 const vecng<3,FT>& p, const Matrix<4,FT>& M
1030 ) {
1031 vecng<4,FT> q = vecng<4,FT>(p,FT(1.0)) * M;
1032 return vecng<3,FT>(q.x/q.w, q.y/q.w, q.z/q.w);
1033 }
1034
1035
1051 template <class FT> [[deprecated("use operators and vec3/4 conversions")]]
1053 const Matrix<4,FT>& M, const vecng<3,FT>& p
1054 ) {
1055 vecng<4,FT> q = M * vecng<4,FT>(p,FT(1.0));
1056 return vecng<3,FT>(q.x/q.w, q.y/q.w, q.z/q.w);
1057 }
1058
1069 template <class FT> [[deprecated("use operators and vec3/4 conversions")]]
1071 const vecng<4,FT>& v, const Matrix<4,FT>& M
1072 ) {
1073 return v*M;
1074 }
1075
1076#endif
1077
1078 /******************************************************************/
1079
1089 mat4 result;
1090 result.load_identity();
1091 result(3,0) = T.x;
1092 result(3,1) = T.y;
1093 result(3,2) = T.z;
1094 return result;
1095 }
1096
1105 inline mat4 create_scaling_matrix(double s) {
1106 mat4 result;
1107 result.load_identity();
1108 result(0,0) = s;
1109 result(1,1) = s;
1110 result(2,2) = s;
1111 return result;
1112 }
1113
1114 /******************************************************************/
1115
1119 struct Ray {
1125 Ray(vec3 O, vec3 D) : origin(O), direction(D) {
1126 }
1127
1131 }
1132 vec3 origin;
1133 vec3 direction;
1134 };
1135
1136 /******************************************************************/
1137
1138}
1139
1140#endif
Axis-aligned bounding box.
Definition geometry.h:845
vec2 hi() const
Gets the higher bounds.
Definition geometry.h:894
void add(const vec2 &p)
Adds a point to this box.
Definition geometry.h:946
vec2 lo() const
Gets the lower bounds.
Definition geometry.h:886
void clear()
Makes this box empty.
Definition geometry.h:933
bool contains(const vec2 &b) const
Tests whether a box contains a point.
Definition geometry.h:903
void enlarge(double d)
Enlarges the box.
Definition geometry.h:920
Box2d(const vec2 &lo, const vec2 &hi)
Constructs a box from lower and upper bounds.
Definition geometry.h:875
Box2d(double x1, double y1, double x2, double y2)
Constructs a box from lower and upper bounds.
Definition geometry.h:863
Box2d()
Constructs an uninitialized Box2d.
Definition geometry.h:855
Axis-aligned bounding box.
Definition geometry.h:689
Box(const vec3 &lo, const vec3 &hi)
Constructs a box from lower and upper bounds.
Definition geometry.h:721
void add(const vec3 &p)
Adds a point to this box.
Definition geometry.h:796
vec3 lo() const
Gets the lower bounds.
Definition geometry.h:734
void clear()
Makes this box empty.
Definition geometry.h:783
vec3 hi() const
Gets the higher bounds.
Definition geometry.h:742
Box()
Constructs an uninitialized box.
Definition geometry.h:699
bool contains(const vec3 &b) const
Tests whether a box contains a point.
Definition geometry.h:751
void enlarge(double d)
Enlarges the box.
Definition geometry.h:768
Box(double x1, double y1, double z1, double x2, double y2, double z2)
Constructs a box from lower and upper bounds.
Definition geometry.h:707
A matrix type.
Definition matrix.h:66
void load_identity()
Sets the matrix to identity.
Definition matrix.h:145
Generic maths vector.
Definition vecg.h:74
vecng< 3, T > cross(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the cross product of 2 vectors.
Definition vecg.h:1009
T length2(const vecng< DIM, T > &v)
Gets the square norm of a vector.
Definition vecg.h:458
T * data()
Gets modifiable vector data.
Definition vecg.h:165
Common include file, providing basic definitions. Should be included before anything else by all head...
Generic matrix type.
Geometric functions and utilities.
Definition geometry.h:201
double det(const vec2 &a, const vec2 &b)
Computes the determinant of two vectors.
Definition geometry.h:312
double triangle_signed_area(const vec2 &p1, const vec2 &p2, const vec2 &p3)
Computes the area of a 2d triangle.
Definition geometry.h:400
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.
Definition geometry.h:602
double tetra_volume(const vec3 &p1, const vec3 &p2, const vec3 &p3, const vec3 &p4)
Computes the volume of a 3d tetrahedron.
Definition geometry.h:520
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.
Definition geometry.h:335
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.
Definition geometry.h:583
double cos_angle(const vec3 &a, const vec3 &b)
Computes the cosine of the angle between two 3d vectors.
Definition geometry.h:269
double triangle_area(const vec3 &p1, const vec3 &p2, const vec3 &p3)
Computes the area of a 3d triangle.
Definition geometry.h:368
double triangle_signed_area_2d(const double *p1, const double *p2, const double *p3)
Computes the area of a 2d triangle.
Definition geometry.h:382
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.
Definition geometry.h:554
bool has_nan(const vec3 &v)
Tests whether a 3d vector has a NaN (not a number) coordinate.
Definition geometry.h:449
double triangle_area_2d(const double *p1, const double *p2, const double *p3)
Computes the area of a 2d triangle.
Definition geometry.h:426
double angle(const vec3 &a, const vec3 &b)
Computes the angle between two 3d vectors.
Definition geometry.h:286
double triangle_area_3d(const double *p1, const double *p2, const double *p3)
Computes the area of a 3d triangle.
Definition geometry.h:346
double tetra_signed_volume(const vec3 &p1, const vec3 &p2, const vec3 &p3, const vec3 &p4)
Computes the signed volume of a 3d tetrahedron.
Definition geometry.h:483
vec3 barycenter(const vec3 &p1, const vec3 &p2)
Computes the barycenter of two points in 3d.
Definition geometry.h:209
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.
constexpr float64 max_float64()
Gets 64 bits float maximum positive value.
Definition numeric.h:177
bool is_nan(float32 x)
Checks whether a 32 bits float is "not a number".
Global Vorpaline namespace.
Definition basic.h:55
Matrix< 4, Numeric::float64 > mat4
Represents a 4x4 matrix.
Definition geometry.h:153
bool bboxes_overlap(const Box &B1, const Box &B2)
Tests whether two Boxes have a non-empty intersection.
Definition geometry.h:814
vecng< 3, Numeric::float32 > vec3f
Represents points and vectors in 3d with single-precision coordinates.
Definition geometry.h:85
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors. \relates vecng
Definition vecg.h:995
vecng< 4, Numeric::float32 > vec4f
Represents points and vectors in 4d with single-precision coordinates.
Definition geometry.h:92
vecng< 3, FT > transform_vector(const vecng< 3, FT > &v, const Matrix< 4, FT > &M)
Applies a 3d transform to a 3d vector.
Definition geometry.h:1006
void bbox_union(Box &target, const Box &B1, const Box &B2)
Computes the smallest Box that encloses two Boxes.
Definition geometry.h:833
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
Definition geometry.h:65
T det3x3(const T &a11, const T &a12, const T &a13, const T &a21, const T &a22, const T &a23, const T &a31, const T &a32, const T &a33)
Computes a three-by-three determinant.
Definition determinant.h:69
vecng< 3, FT > transform_point(const vecng< 3, FT > &p, const Matrix< 4, FT > &M)
Applies a 3d transform to a 3d point.
Definition geometry.h:1028
T det4x4(const T &a11, const T &a12, const T &a13, const T &a14, const T &a21, const T &a22, const T &a23, const T &a24, const T &a31, const T &a32, const T &a33, const T &a34, const T &a41, const T &a42, const T &a43, const T &a44)
Computes a four-by-four determinant.
Definition determinant.h:85
void geo_clamp(T &x, T min, T max)
Clamps a value to a range.
Definition numeric.h:326
vecng< 3, Numeric::uint32 > vec3u
Represents points and vectors in 3d with unsigned integer coordinates.
Definition geometry.h:128
mat4 create_scaling_matrix(double s)
Creates a scaling matrix.
Definition geometry.h:1105
vecng< 3, Numeric::int32 > vec3i
Represents points and vectors in 3d with integer coordinates.
Definition basic.h:91
vecng< 2, Numeric::uint32 > vec2u
Represents points and vectors in 2d with unsigned integer coordinates.
Definition geometry.h:121
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:341
double det(const mat2 &M)
Computes the determinant of a 2x2 matrix.
Definition geometry.h:162
vecng< 4, Numeric::float64 > vec4
Represents points and vectors in 4d.
Definition geometry.h:71
mat4 create_translation_matrix(const vec3 &T)
Creates a translation matrix from a vector.
Definition geometry.h:1088
vecng< 2, Numeric::int32 > vec2i
Represents points and vectors in 2d with integer coordinates.
Definition geometry.h:100
T det2x2(const T &a11, const T &a12, const T &a21, const T &a22)
Computes a two-by-two determinant.
Definition determinant.h:58
Matrix< 3, Numeric::float64 > mat3
Represents a 3x3 matrix.
Definition geometry.h:147
vecng< 4, Numeric::uint32 > vec4u
Represents points and vectors in 4d with unsigned integer coordinates.
Definition geometry.h:135
vecng< 2, Numeric::float32 > vec2f
Represents points and vectors in 2d with single-precision coordinates.
Definition geometry.h:78
vecng< 2, Numeric::float64 > vec2
Represents points and vectors in 2d.
Definition geometry.h:59
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.
Definition numeric.h:375
vecng< 4, Numeric::int32 > vec4i
Represents points and vectors in 4d with integer coordinates.
Definition geometry.h:114
Matrix< 2, Numeric::float64 > mat2
Represents a 2x2 matrix.
Definition geometry.h:141
Plane(const vec3 &p1, const vec3 &p2, const vec3 &p3)
Constructs the plane passing through three points.
Definition geometry.h:635
Plane(const vec3 &p, const vec3 &n)
Constructs a plane passign through a point and orthogonal to a vector.
Definition geometry.h:649
Plane(double a_in, double b_in, double c_in, double d_in)
Constructs a plane from the coefficients of its equation.
Definition geometry.h:659
Plane()
Constructs an uninitialized plane.
Definition geometry.h:671
vec3 normal() const
Gets the normal vector of the plane.
Definition geometry.h:677
Ray()
Ray constructor.
Definition geometry.h:1130
Ray(vec3 O, vec3 D)
Ray constructor.
Definition geometry.h:1125