Easy3D 2.5.3
oriented_line.h
1/********************************************************************
2 * Copyright (C) 2015-2021 by Liangliang Nan <liangliang.nan@gmail.com>
3 * Copyright (C) 2000-2005 INRIA - Project ALICE
4 *
5 * The code in this file is partly from OGF/Graphite (2.0 alpha-4) with
6 * modifications and enhancement:
7 * https://gforge.inria.fr/forum/forum.php?forum_id=11459
8 * The original code was distributed under the GNU GPL license.
9 ********************************************************************/
10
11#ifndef EASY3D_CORE_ORIENTED_LINE_H
12#define EASY3D_CORE_ORIENTED_LINE_H
13
14#include <easy3d/core/vec.h>
15
16
17namespace easy3d {
18
20 enum Sign {
21 NEGATIVE = -1,
22 ZERO = 0,
23 POSITIVE = 1,
24 };
25
27 template<class T>
28 inline Sign sign(T x) {
29 return (x > 0) ? POSITIVE : ((x < 0) ? NEGATIVE : ZERO);
30 }
31
42 template<class FT>
44 public:
45 typedef Vec<3, FT> Point;
46
48 GenericOrientedLine(const Point &p, const Point &q);
50
58
59 private:
60 FT pi_[6];
61 };
62
63 //_________________________________________________________
64
65 template<class FT>
66 inline
68 // There are several conventions for defining plucker coordinates,
69 // this one is introduced in : Marco Pellegrini, Stabbing and
70 // ray-shooting in 3-dimensional space. In Proc. 6th ACM Symposium
71 // on Computational Geometry, pages 177-186, 1990.
72 // I think that it is possible to have a more symmetric formulation
73 // of plucker coordinates, leading to a more symmetric side()
74 // predicate, but I have no time to investigate this.
75 pi_[0] = p.x * q.y - p.y * q.x;
76 pi_[1] = p.x * q.z - p.z * q.x;
77 pi_[2] = p.x - q.x;
78 pi_[3] = p.y * q.z - p.z * q.y;
79 pi_[4] = p.z - q.z;
80 pi_[5] = q.y - p.y;
81 }
82
83 template<class FT>
84 inline
86 pi_[0] = 0;
87 pi_[1] = 0;
88 pi_[2] = 0;
89 pi_[3] = 0;
90 pi_[4] = 0;
91 pi_[5] = 0;
92 }
93
94
95 template<class FT>
96 inline
98 // Note: the order might seem strange, but product between
99 // lines in plucker coordinates is a permuted cross product.
100 FT cross_product =
101 a.pi_[0] * b.pi_[4] +
102 a.pi_[1] * b.pi_[5] +
103 a.pi_[2] * b.pi_[3] +
104 a.pi_[4] * b.pi_[0] +
105 a.pi_[5] * b.pi_[1] +
106 a.pi_[3] * b.pi_[2];
107
108 return sign(cross_product);
109 }
110
111}
112
113#endif //EASY3D_CORE_ORIENTED_LINE_H
OrientedLine implements plucker coordinates, which enables oriented lines to be compared.
Definition: oriented_line.h:43
static Sign side(const GenericOrientedLine< FT > &a, const GenericOrientedLine< FT > &b)
Definition: oriented_line.h:97
Base class for vector types. It provides generic functionality for N dimensional vectors.
Definition: vec.h:34
Definition: collider.cpp:182
Sign
The sign.
Definition: oriented_line.h:20
Sign sign(T x)
returns the sign of a value.
Definition: oriented_line.h:28