libigl v2.5.0
Loading...
Searching...
No Matches
tri_tri_intersect.h
Go to the documentation of this file.
1// This file is part of libigl, a simple c++ geometry processing library.
2//
3// Copyright (C) 2021 Vladimir S. FONOV <vladimir.fonov@gmail.com>
4//
5// This Source Code Form is subject to the terms of the Mozilla Public License
6// v. 2.0. If a copy of the MPL was not distributed with this file, You can
7// obtain one at http://mozilla.org/MPL/2.0/
8
9/*
10*
11* C++ version based on the routines published in
12* "Fast and Robust Triangle-Triangle Overlap Test
13* Using Orientation Predicates" P. Guigue - O. Devillers
14*
15* Works with Eigen data structures instead of plain C arrays
16* returns bool values
17*
18* Code is rewritten to get rid of the macros and use C++ lambda and
19* inline functions instead
20*
21* Original notice:
22*
23* Triangle-Triangle Overlap Test Routines
24* July, 2002
25* Updated December 2003
26*
27* Updated by Vladimir S. FONOV
28* March, 2023
29*
30* This file contains C implementation of algorithms for
31* performing two and three-dimensional triangle-triangle intersection test
32* The algorithms and underlying theory are described in
33*
34* "Fast and Robust Triangle-Triangle Overlap Test
35* Using Orientation Predicates" P. Guigue - O. Devillers
36*
37* Journal of Graphics Tools, 8(1), 2003
38*
39* Several geometric predicates are defined. Their parameters are all
40* points. Each point is an array of two or three double precision
41* floating point numbers. The geometric predicates implemented in
42* this file are:
43*
44* int tri_tri_overlap_test_3d(p1,q1,r1,p2,q2,r2)
45* int tri_tri_overlap_test_2d(p1,q1,r1,p2,q2,r2)
46*
47* int tri_tri_intersection_test_3d(p1,q1,r1,p2,q2,r2,
48* coplanar,source,target)
49*
50* is a version that computes the segment of intersection when
51* the triangles overlap (and are not coplanar)
52*
53* each function returns 1 if the triangles (including their
54* boundary) intersect, otherwise 0
55*
56*
57* Other information are available from the Web page
58* http://www.acm.org/jgt/papers/GuigueDevillers03/
59*
60*/
61
62/*
63Original MIT License (from https://github.com/erich666/jgt-code)
64Copyright (c) <year> <copyright holders>
65
66Permission is hereby granted, free of charge, to any person obtaining a copy of this software
67and associated documentation files (the "Software"), to deal in the Software without
68restriction, including without limitation the rights to use, copy, modify, merge, publish,
69distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
70Software is furnished to do so, subject to the following conditions:
71
72The above copyright notice and this permission notice shall be included in all copies or
73substantial portions of the Software.
74
75THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
76BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
77NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
78DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
79FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
80
81*/
82
83#pragma once
84#ifndef IGL_TRI_TRI_INTERSECT_H
85#define IGL_TRI_TRI_INTERSECT_H
86
87#include "igl_inline.h"
88#include <Eigen/Core>
89
90namespace igl {
91
92
93// Three-dimensional Triangle-Triangle overlap test
94// if triangles are co-planar
95//
96// Input:
97// p1,q1,r1 - vertices of the 1st triangle (3D)
98// p2,q2,r2 - vertices of the 2nd triangle (3D)
99//
100// Output:
101//
102// Return true if two triangles overlap
103template <typename DerivedP1,typename DerivedQ1,typename DerivedR1,
104typename DerivedP2,typename DerivedQ2,typename DerivedR2>
106 const Eigen::MatrixBase<DerivedP1> & p1,
107 const Eigen::MatrixBase<DerivedQ1> & q1,
108 const Eigen::MatrixBase<DerivedR1> & r1,
109 const Eigen::MatrixBase<DerivedP2> & p2,
110 const Eigen::MatrixBase<DerivedQ2> & q2,
111 const Eigen::MatrixBase<DerivedR2> & r2);
112
113
114// Three-dimensional Triangle-Triangle Intersection Test
115// additionaly computes the segment of intersection of the two triangles if it exists.
116// coplanar returns whether the triangles are coplanar,
117// source and target are the endpoints of the line segment of intersection
118//
119// Input:
120// p1,q1,r1 - vertices of the 1st triangle (3D)
121// p2,q2,r2 - vertices of the 2nd triangle (3D)
122//
123// Output:
124// coplanar - flag if two triangles are coplanar
125// source - 1st point of intersection (if exists)
126// target - 2nd point in intersection (if exists)
127//
128// Return true if two triangles intersect
129template <typename DerivedP1,typename DerivedQ1,typename DerivedR1,
130typename DerivedP2,typename DerivedQ2,typename DerivedR2,
131typename DerivedS,typename DerivedT>
133 const Eigen::MatrixBase<DerivedP1> & p1, const Eigen::MatrixBase<DerivedQ1> & q1, const Eigen::MatrixBase<DerivedR1> & r1,
134 const Eigen::MatrixBase<DerivedP2> & p2, const Eigen::MatrixBase<DerivedQ2> & q2, const Eigen::MatrixBase<DerivedR2> & r2,
135 bool & coplanar,
136 Eigen::MatrixBase<DerivedS> & source,
137 Eigen::MatrixBase<DerivedT> & target );
138
139
140
141// Two dimensional Triangle-Triangle Overlap Test
142// Input:
143// p1,q1,r1 - vertices of the 1st triangle (2D)
144// p2,q2,r2 - vertices of the 2nd triangle (2D)
145//
146// Output:
147// Return true if two triangles overlap
148template <typename DerivedP1,typename DerivedQ1,typename DerivedR1,
149typename DerivedP2,typename DerivedQ2,typename DerivedR2>
151 const Eigen::MatrixBase<DerivedP1> &p1, const Eigen::MatrixBase<DerivedQ1> &q1, const Eigen::MatrixBase<DerivedR1> &r1,
152 const Eigen::MatrixBase<DerivedP2> &p2, const Eigen::MatrixBase<DerivedQ2> &q2, const Eigen::MatrixBase<DerivedR2> &r2);
153
154
155};
156
157#ifndef IGL_STATIC_LIBRARY
158# include "tri_tri_intersect.cpp"
159#endif
160
161#endif // IGL_TRI_TRI_INTERSECT_H
#define IGL_INLINE
Definition igl_inline.h:15
Definition AABB.h:17
bool tri_tri_intersection_test_3d(const Eigen::MatrixBase< DerivedP1 > &p1, const Eigen::MatrixBase< DerivedQ1 > &q1, const Eigen::MatrixBase< DerivedR1 > &r1, const Eigen::MatrixBase< DerivedP2 > &p2, const Eigen::MatrixBase< DerivedQ2 > &q2, const Eigen::MatrixBase< DerivedR2 > &r2, bool &coplanar, Eigen::MatrixBase< DerivedS > &source, Eigen::MatrixBase< DerivedT > &target)
bool tri_tri_overlap_test_3d(const Eigen::MatrixBase< DerivedP1 > &p1, const Eigen::MatrixBase< DerivedQ1 > &q1, const Eigen::MatrixBase< DerivedR1 > &r1, const Eigen::MatrixBase< DerivedP2 > &p2, const Eigen::MatrixBase< DerivedQ2 > &q2, const Eigen::MatrixBase< DerivedR2 > &r2)
bool tri_tri_overlap_test_2d(const Eigen::MatrixBase< DerivedP1 > &p1, const Eigen::MatrixBase< DerivedQ1 > &q1, const Eigen::MatrixBase< DerivedR1 > &r1, const Eigen::MatrixBase< DerivedP2 > &p2, const Eigen::MatrixBase< DerivedQ2 > &q2, const Eigen::MatrixBase< DerivedR2 > &r2)