159{
162
163 for (size_t i=0; i<2; ++i)
165
166 const float sqr_radius =
pow(
radius, 2.f);
167
168
170 float sqr_dist_limit =
pow(
height/2.f, 2.f) + sqr_radius ;
171 if (ray.squaredDistance(center) > sqr_dist_limit)
172 return false;
173
174
175
176
177 size_t found = 0;
180 for (size_t i=1; i<=1; --i) {
182 if (i == 0) {
183
184
186 }
189
190 if ((cylinder_center-
intersection).squaredNorm() < sqr_radius) {
191 out[found].first = ray.intersectionParameter(base);
192 out[found].second = (i==0 ? 1. : -1.) *
normal.cast<
double>();
193 ++found;
194 }
195 }
196 }
197 else
198 {
199
200
202 }
203
204
205 if (found != 2 && !
is_approx(std::abs(ray.direction().dot(
normal)), 1.f)) {
206
208 Vec3f proj_dir = base.
projection(ray.origin()+ray.direction())-proj_origin;
209
210 float par_scale = proj_dir.norm();
211 proj_dir = proj_dir/par_scale;
213
214
215 Vec3f closest = projected_ray.projection(
pos);
216 float dist =
sqrt((sqr_radius - (closest-
pos).squaredNorm()));
217
218
219 for (int i=-1; i<=1 && found !=2; i+=2) {
220 Vec3f isect = closest + i*
dist * projected_ray.direction();
221 Vec3f to_isect = isect-proj_origin;
222 float par = to_isect.norm() / par_scale;
223 if (to_isect.normalized().dot(proj_dir.normalized()) < 0.f)
224 par *= -1.f;
225 Vec3d hit_normal = (
pos-isect).normalized().cast<
double>();
226 isect = ray.pointAt(par);
227
229 if (vert_dist > 0.f && vert_dist <
height) {
230 out[found].first = par;
231 out[found].second = hit_normal;
232 ++found;
233 }
234 }
235 }
236
237
238
239 if (found != 2)
240 return false;
241
242
243 if (out[0].first > out[1].first)
244 std::swap(out[0], out[1]);
245
246 return true;
247}
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition ArrayCwiseUnaryOps.h:152
static constexpr double infty()
Definition AABBMesh.hpp:80
EIGEN_DEVICE_FUNC Scalar signedDistance(const VectorType &p) const
Definition Hyperplane.h:143
EIGEN_DEVICE_FUNC VectorType projection(const VectorType &p) const
Definition Hyperplane.h:152
A parametrized line.
Definition ParametrizedLine.h:31
A hyperplane.
Definition Hyperplane.h:35
static constexpr double EPSILON
Definition libslic3r.h:51
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half &a, const half &b)
Definition Half.h:477
T dist(const boost::polygon::point_data< T > &p1, const boost::polygon::point_data< T > &p2)
Definition Geometry.cpp:280
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition SpatIndex.hpp:15
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:49
Slic3r::Polygons intersection(const Slic3r::Polygon &subject, const Slic3r::Polygon &clip, ApplySafetyOffset do_safety_offset)
Definition ClipperUtils.cpp:686
constexpr bool is_approx(Number value, Number test_value, Number precision=EPSILON)
Definition libslic3r.h:271