12 #if !defined(KRATOS_CURVE_AXIS_INTERSECTION_INCLUDED )
13 #define KRATOS_CURVE_AXIS_INTERSECTION_INCLUDED
26 template<
class TNodeType>
40 static double BisectionToAxis(
42 double IntersectionAxis,
46 double Tolerance = 1
e-6)
48 double parameter_smaller, parameter_bigger;
51 parameter_1[0] = Parameter1;
53 parameter_2[0] = Parameter2;
57 double distance = point_1[AxisDirectionIndex] - IntersectionAxis;
59 parameter_smaller = parameter_1[0];
60 parameter_bigger = parameter_2[0];
63 parameter_smaller = parameter_2[0];
64 parameter_bigger = parameter_1[0];
70 new_parameter[0] = (parameter_smaller + parameter_bigger) / 2;
73 distance = point_new[AxisDirectionIndex] - IntersectionAxis;
75 if (std::abs(distance) < Tolerance) {
76 return new_parameter[0];
79 parameter_smaller = new_parameter[0];
81 parameter_bigger = new_parameter[0];
87 static void GetSpanIndex(
88 const std::vector<double>& rAxis,
93 bool Ascending =
true)
98 <<
"Point of polygon not within the axis boundaries. Axis are: "
99 << rAxis <<
". Searched parameter is: " << Parameter << std::endl;
104 if ((Parameter >= rMin) && (Parameter < rMax)) {
113 <<
"Point of polygon not within the axis boundaries. Axis are: "
114 << rAxis <<
". Searched parameter is: " << Parameter << std::endl;
119 if ((Parameter >= rMin) && (Parameter < rMax)) {
131 static void SortUnique(
132 std::vector<double>& rIntersectionParameters,
133 const double Tolerance)
135 std::sort(std::begin(rIntersectionParameters),
std::end(rIntersectionParameters));
137 auto last = std::unique(std::begin(rIntersectionParameters),
std::end(rIntersectionParameters),
138 [=](
double a,
double b) {
return b -
a < Tolerance; });
140 auto nb_unique = std::distance(std::begin(rIntersectionParameters), last);
142 rIntersectionParameters.resize(nb_unique);
147 std::vector<double>& rIntersectionParameters,
151 const std::vector<double>& rAxis1,
152 const std::vector<double>& rAxis2,
153 const double Tolerance)
155 rIntersectionParameters.clear();
156 rIntersectionParameters.push_back(Start);
160 rGeometry, 100, Start, End);
163 <<
"Size of axis vector 1 is: " << rAxis1.size() <<
". It needs to be at least of size 2. "
164 <<
"It must contain the boundaries, too. Axis vector: " << rAxis1
167 <<
"Size of axis vector 2 is: " << rAxis2.size() <<
". It needs to be at least of size 2. "
168 <<
"It must contain the boundaries, too. Axis vector: " << rAxis1
171 bool ascending_1 = (rAxis1[0] < rAxis1[1]);
172 bool ascending_2 = (rAxis2[0] < rAxis2[1]);
177 double max_1 = std::numeric_limits<double>::lowest();
179 double max_2 = std::numeric_limits<double>::lowest();
180 GetSpanIndex(rAxis1, axis_index_1, min_1, max_1, std::get<1>(polygon[0])[0], ascending_1);
181 GetSpanIndex(rAxis2, axis_index_2, min_2, max_2, std::get<1>(polygon[0])[1], ascending_2);
185 if (std::get<1>(polygon[
i])[0] < min_1 - Tolerance) {
186 double intersection_parameter = BisectionToAxis(
188 std::get<0>(polygon[
i - 1]), std::get<0>(polygon[
i]), 0, Tolerance);
189 rIntersectionParameters.push_back(intersection_parameter);
190 GetSpanIndex(rAxis1, axis_index_1, min_1, max_1, std::get<1>(polygon[
i])[0], ascending_1);
192 else if (std::get<1>(polygon[
i])[0] > max_1 + Tolerance) {
193 double intersection_parameter = BisectionToAxis(
195 std::get<0>(polygon[
i - 1]), std::get<0>(polygon[
i]), 0, Tolerance);
196 rIntersectionParameters.push_back(intersection_parameter);
197 GetSpanIndex(rAxis1, axis_index_1, min_1, max_1, std::get<1>(polygon[
i])[0], ascending_1);
200 if (std::get<1>(polygon[
i])[1] < min_2 - Tolerance) {
201 double intersection_parameter = BisectionToAxis(
203 std::get<0>(polygon[
i - 1]), std::get<0>(polygon[
i]), 1, Tolerance);
204 rIntersectionParameters.push_back(intersection_parameter);
205 GetSpanIndex(rAxis2, axis_index_2, min_2, max_2, std::get<1>(polygon[
i])[1], ascending_2);
207 else if (std::get<1>(polygon[
i])[1] > max_2 + Tolerance) {
208 double intersection_parameter = BisectionToAxis(
210 std::get<0>(polygon[
i - 1]), std::get<0>(polygon[
i]), 1, Tolerance);
211 rIntersectionParameters.push_back(intersection_parameter);
212 GetSpanIndex(rAxis2, axis_index_2, min_2, max_2, std::get<1>(polygon[
i])[1], ascending_2);
217 if (std::abs(rIntersectionParameters[rIntersectionParameters.size() - 1] - End) > Tolerance)
218 rIntersectionParameters.push_back(End);
221 SortUnique(rIntersectionParameters, Tolerance);
Definition: curve_axis_intersection.h:28
GeometryType::Pointer GeometryPointerType
Definition: curve_axis_intersection.h:34
std::size_t SizeType
Definition: curve_axis_intersection.h:30
GeometryType::CoordinatesArrayType CoordinatesArrayType
Definition: curve_axis_intersection.h:35
Geometry< TNodeType > GeometryType
Definition: curve_axis_intersection.h:33
std::size_t IndexType
Definition: curve_axis_intersection.h:31
static void ComputeAxisIntersection(std::vector< double > &rIntersectionParameters, const GeometryType &rGeometry, double Start, double End, const std::vector< double > &rAxis1, const std::vector< double > &rAxis2, const double Tolerance)
Definition: curve_axis_intersection.h:146
CurveTessellation< PointerVector< TNodeType > > CurveTesselationType
Definition: curve_axis_intersection.h:37
Definition: curve_tessellation.h:32
static TessellationType ComputePolygon(const GeometryType &rGeometry, const SizeType NumberOfPoints, const double Start, const double End)
Definition: curve_tessellation.h:286
Geometry base class.
Definition: geometry.h:71
virtual CoordinatesArrayType & GlobalCoordinates(CoordinatesArrayType &rResult, CoordinatesArrayType const &LocalCoordinates) const
Definition: geometry.h:2377
Short class definition.
Definition: array_1d.h:61
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
end
Definition: DEM_benchmarks.py:180
static double max(double a, double b)
Definition: GeometryFunctions.h:79
static double min(double a, double b)
Definition: GeometryFunctions.h:71
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
a
Definition: generate_stokes_twofluid_element.py:77
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31