Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
determinant.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_DETERMINANT
41 #define GEOGRAM_BASIC_DETERMINANT
42 
43 #include <geogram/basic/common.h>
44 
50 namespace GEO {
51 
52  /************************************************************************/
53 
57  template <class T>
58  inline T det2x2(
59  const T& a11, const T& a12,
60  const T& a21, const T& a22
61  ) {
62  return a11*a22-a12*a21 ;
63  }
64 
68  template <class T>
69  inline T det3x3(
70  const T& a11, const T& a12, const T& a13,
71  const T& a21, const T& a22, const T& a23,
72  const T& a31, const T& a32, const T& a33
73  ) {
74  return
75  a11*det2x2(a22,a23,a32,a33)
76  -a21*det2x2(a12,a13,a32,a33)
77  +a31*det2x2(a12,a13,a22,a23);
78  }
79 
80 
84  template <class T>
85  inline T det4x4(
86  const T& a11, const T& a12, const T& a13, const T& a14,
87  const T& a21, const T& a22, const T& a23, const T& a24,
88  const T& a31, const T& a32, const T& a33, const T& a34,
89  const T& a41, const T& a42, const T& a43, const T& a44
90  ) {
91  T m12 = a21*a12 - a11*a22;
92  T m13 = a31*a12 - a11*a32;
93  T m14 = a41*a12 - a11*a42;
94  T m23 = a31*a22 - a21*a32;
95  T m24 = a41*a22 - a21*a42;
96  T m34 = a41*a32 - a31*a42;
97 
98  T m123 = m23*a13 - m13*a23 + m12*a33;
99  T m124 = m24*a13 - m14*a23 + m12*a43;
100  T m134 = m34*a13 - m14*a33 + m13*a43;
101  T m234 = m34*a23 - m24*a33 + m23*a43;
102 
103  return (m234*a14 - m134*a24 + m124*a34 - m123*a44);
104  }
105 }
106 
107 #endif
Common include file, providing basic definitions. Should be included before anything else by all head...
Global Vorpaline namespace.
Definition: basic.h:55
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
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
T det2x2(const T &a11, const T &a12, const T &a21, const T &a22)
Computes a two-by-two determinant.
Definition: determinant.h:58