Visual Computing Library  devel
Loading...
Searching...
No Matches
visibility.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_ALGORITHMS_CORE_VISIBILITY_H
24#define VCL_ALGORITHMS_CORE_VISIBILITY_H
25
26#include <vclib/space/core.h>
27
28namespace vcl {
29
46template<Point3Concept PointType>
48 const PointType& p0,
49 const PointType& p1,
50 const PointType& p2,
51 const PointType& p)
52{
53 return (p1 - p0).cross(p2 - p0).dot(p - p0);
54}
55
69template<Triangle3Concept TriangleType, Point3Concept PointType>
70auto halfSpaceDeterminant(const TriangleType& triangle, const PointType& point)
71{
73 triangle.point(0), triangle.point(1), triangle.point(2), point);
74}
75
87template<Point3Concept PointType>
89 const PointType& p0,
90 const PointType& p1,
91 const PointType& p2)
92{
93 PointType c = (p1 - p0).cross(p2 - p0);
94 return c.squaredNorm() == 0;
95}
96
109template<Point3Concept PointType>
111 const PointType& p0,
112 const PointType& p1,
113 const PointType& p2,
114 const PointType& p3)
115{
116 return halfSpaceDeterminant(p0, p1, p2, p3) == 0;
117}
118
131template<Triangle3Concept TriangleType, Point3Concept PointType>
133 const TriangleType& triangle,
134 const PointType& point)
135{
136 return halfSpaceDeterminant(triangle, point) > 0;
137}
138
152template<Point3Concept PointType>
154 const PointType& p0,
155 const PointType& p1,
156 const PointType& p2,
157 const PointType& p)
158{
159 return halfSpaceDeterminant(p0, p1, p2, p) > 0;
160}
161
162} // namespace vcl
163
164#endif // VCL_ALGORITHMS_CORE_VISIBILITY_H
A class representing a box in N-dimensional space.
Definition box.h:46
bool arePointsCollinear(const PointType &p0, const PointType &p1, const PointType &p2)
Checks if 3 points are collinear.
Definition visibility.h:88
auto halfSpaceDeterminant(const PointType &p0, const PointType &p1, const PointType &p2, const PointType &p)
Compute the determinant of the half-space defined by the triangle (p1, p2, p3) and the point p.
Definition visibility.h:47
bool arePointsCoplanar(const PointType &p0, const PointType &p1, const PointType &p2, const PointType &p3)
Checks if 4 points are coplanar.
Definition visibility.h:110
bool trianglePointVisibility(const TriangleType &triangle, const PointType &point)
Checks if a point is visible from a triangle, i.e., if the point is in the half-space defined by the ...
Definition visibility.h:132