Wildmeshing Toolkit
Loading...
Searching...
No Matches
Circle.hpp
1#pragma once
2#include <queue>
3#include "TopoOffsetTriMesh.h"
4
5
6namespace wmtk::components::topological_offset {
7
8
9class Circle
10{
11private:
12 Vector2d m_c;
13 double m_r;
14
15public:
19 static void
20 fit_square(const Vector2d& p1, const Vector2d& p2, const Vector2d& p3, Vector2d& c, double& l)
21 {
22 MatrixXd V(3, 2);
23 V.row(0) = p1;
24 V.row(1) = p2;
25 V.row(2) = p3;
26 Eigen::RowVectorXd mins = V.colwise().minCoeff();
27 Eigen::RowVectorXd maxs = V.colwise().maxCoeff();
28 if ((maxs(0) - mins(0)) > (maxs(1) - mins(1))) { // x span bigger than y span
29 l = maxs(0) - mins(0);
30 } else {
31 l = maxs(1) - mins(1);
32 }
33 c(0) = (maxs(0) + mins(0)) / 2.0;
34 c(1) = (maxs(1) + mins(1)) / 2.0;
35 }
36
37 Circle(const Vector2d& c, const double r)
38 : m_c(c)
39 , m_r(r)
40 {}
41
42 Circle(const TopoOffsetTriMesh& mesh, const size_t f_id)
43 {
44 auto vs = mesh.oriented_tri_vids(f_id);
45 double side_length;
46 Vector2d center;
48 mesh.m_vertex_attribute[vs[0]].m_posf,
49 mesh.m_vertex_attribute[vs[1]].m_posf,
50 mesh.m_vertex_attribute[vs[2]].m_posf,
51 center,
52 side_length);
53 m_c(0) = center(0);
54 m_c(1) = center(1);
55 m_r = side_length / sqrt(2.0);
56 }
57
61 double radius() const { return m_r; }
62
66 Vector2d center() const { return m_c; }
67
71 void refine(std::queue<Circle>& q) const
72 {
73 double c_off_l = m_r / (2 * sqrt(2.0));
74 double new_r = m_r / 2.0;
75 q.emplace(m_c + (c_off_l * Vector2d(-1, -1)), new_r);
76 q.emplace(m_c + (c_off_l * Vector2d(-1, 1)), new_r);
77 q.emplace(m_c + (c_off_l * Vector2d(1, -1)), new_r);
78 q.emplace(m_c + (c_off_l * Vector2d(1, 1)), new_r);
79 }
80
84 bool overlaps_tri(const TopoOffsetTriMesh& mesh, const size_t f_id) const
85 {
86 auto vs = mesh.oriented_tri_vids(f_id);
87 Vector2d p0 = mesh.m_vertex_attribute[vs[0]].m_posf;
88 Vector2d p1 = mesh.m_vertex_attribute[vs[1]].m_posf;
89 Vector2d p2 = mesh.m_vertex_attribute[vs[2]].m_posf;
90
91 MatrixXd V(3, 2);
92 V.row(0) = p0;
93 V.row(1) = p1;
94 V.row(2) = p2;
95 MatrixXi F(1, 3);
96 F << 0, 1, 2;
97 double dist2;
98 Vector2d closest_point;
99 igl::point_simplex_squared_distance<2>(m_c, V, F, 0, dist2, closest_point);
100 return (dist2 < (m_r * m_r));
101 }
102};
103
104
105} // namespace wmtk::components::topological_offset
std::array< size_t, 3 > oriented_tri_vids(const Tuple &t) const
Get the incident vertices for a triangle.
Definition TriMesh.cpp:1307
static void fit_square(const Vector2d &p1, const Vector2d &p2, const Vector2d &p3, Vector2d &c, double &l)
given 2D triangle, fit square to triangle (return center and side length)
Definition Circle.hpp:20
void refine(std::queue< Circle > &q) const
add refinements of circle to given queue
Definition Circle.hpp:71
double radius() const
get radius of circle
Definition Circle.hpp:61
bool overlaps_tri(const TopoOffsetTriMesh &mesh, const size_t f_id) const
check if circle overlaps given triangle
Definition Circle.hpp:84
Vector2d center() const
get center of circle
Definition Circle.hpp:66