OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Geometry::ArcWelder Namespace Reference

Functions

template<typename Derived, typename Derived2, typename Float>
Eigen::Matrix< Float, 2, 1, Eigen::DontAlign > arc_center (const Eigen::MatrixBase< Derived > &start_pos, const Eigen::MatrixBase< Derived2 > &end_pos, const Float radius, const bool is_ccw)
template<typename FloatType>
size_t arc_discretization_steps (const FloatType radius, const FloatType angle, const FloatType deviation)

Function Documentation

◆ arc_center()

template<typename Derived, typename Derived2, typename Float>
Eigen::Matrix< Float, 2, 1, Eigen::DontAlign > Slic3r::Geometry::ArcWelder::arc_center ( const Eigen::MatrixBase< Derived > & start_pos,
const Eigen::MatrixBase< Derived2 > & end_pos,
const Float radius,
const bool is_ccw )
inline
27{
28 static_assert(Derived::IsVectorAtCompileTime && int(Derived::SizeAtCompileTime) == 2, "arc_center(): first parameter is not a 2D vector");
29 static_assert(Derived2::IsVectorAtCompileTime && int(Derived2::SizeAtCompileTime) == 2, "arc_center(): second parameter is not a 2D vector");
30 static_assert(std::is_same<typename Derived::Scalar, typename Derived2::Scalar>::value, "arc_center(): Both vectors must be of the same type.");
31 static_assert(std::is_same<typename Derived::Scalar, Float>::value, "arc_center(): Radius must be of the same type as the vectors.");
32 assert(radius != 0);
33 using Vector = Eigen::Matrix<Float, 2, 1, Eigen::DontAlign>;
34 auto v = end_pos - start_pos;
35 Float q2 = v.squaredNorm();
36 assert(q2 > 0);
37 Float t2 = sqr(radius) / q2 - Float(.25f);
38 // If the start_pos and end_pos are nearly antipodal, t2 may become slightly negative.
39 // In that case return a centroid of start_point & end_point.
40 Float t = t2 > 0 ? sqrt(t2) : Float(0);
41 auto mid = Float(0.5) * (start_pos + end_pos);
42 Vector vp{ -v.y() * t, v.x() * t };
43 return (radius > Float(0)) == is_ccw ? (mid + vp).eval() : (mid - vp).eval();
44}
static bool is_ccw(const Polygon &poly)
Definition Geometry.hpp:66
Point Vector
Definition Point.hpp:42
constexpr T sqr(T x)
Definition libslic3r.h:301

References Slic3r::Geometry::is_ccw(), and Slic3r::sqr().

Referenced by Slic3r::GCodeProcessor::process_G2_G3().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ arc_discretization_steps()

template<typename FloatType>
size_t Slic3r::Geometry::ArcWelder::arc_discretization_steps ( const FloatType radius,
const FloatType angle,
const FloatType deviation )
51{
52 assert(radius > 0);
53 assert(angle > 0);
54 assert(angle <= FloatType(2. * M_PI));
55 assert(deviation > 0);
56
57 FloatType d = radius - deviation;
58 return d < EPSILON ?
59 // Radius smaller than deviation.
60 ( // Acute angle: a single segment interpolates the arc with sufficient accuracy.
61 angle < M_PI ||
62 // Obtuse angle: Test whether the furthest point (center) of an arc is closer than deviation to the center of a line segment.
63 radius * (FloatType(1.) + cos(M_PI - FloatType(.5) * angle)) < deviation ?
64 // Single segment is sufficient
65 1 :
66 // Two segments are necessary, the middle point is at the center of the arc.
67 2) :
68 size_t(ceil(angle / (2. * acos(d / radius))));
69}
#define EPSILON
Definition ColorUtils.cpp:64
#define M_PI
Definition ExtrusionSimulator.cpp:31
double angle(const Eigen::MatrixBase< Derived > &v1, const Eigen::MatrixBase< Derived2 > &v2)
Definition Point.hpp:138

References Slic3r::angle(), EPSILON, and M_PI.

Referenced by Slic3r::GCodeWriter::_spiral_travel_to_z(), and Slic3r::GCodeProcessor::process_G2_G3().

Here is the call graph for this function:
Here is the caller graph for this function: