69 return p.norm() - radius;
97 Point3D q = p.cwiseAbs() - half_extents;
98 return q.cwiseMax(0.0).norm()
99 + std::min(std::max({q.x(), q.y(), q.z()}), 0.0);
127 Point3D q = p.cwiseAbs() - half_extents;
128 return q.cwiseMax(0.0).norm()
129 + std::min(std::max({q.x(), q.y(), q.z()}), 0.0)
159 [[nodiscard]]
inline double torus(
const Point3D& p,
double major_radius,
double minor_radius) {
160 double qx = std::sqrt(p.x() * p.x() + p.z() * p.z()) - major_radius;
161 return std::sqrt(qx * qx + p.y() * p.y()) - minor_radius;
192 double ba_sq = ba.squaredNorm();
195 return pa.norm() - radius;
197 double h = std::clamp(pa.dot(ba) / ba_sq, 0.0, 1.0);
198 return (pa - ba * h).norm() - radius;
227 [[nodiscard]]
inline double cylinder(
const Point3D& p,
double radius,
double height) {
228 double d_xz = std::sqrt(p.x() * p.x() + p.z() * p.z()) - radius;
229 double d_y = std::abs(p.y()) - height * 0.5;
230 return std::min(std::max(d_xz, d_y), 0.0)
231 + std::sqrt(std::max(d_xz, 0.0) * std::max(d_xz, 0.0)
232 + std::max(d_y, 0.0) * std::max(d_y, 0.0));
262 return p.dot(normal) - offset;
295 Point3D pr(p.x() / radii.x(), p.y() / radii.y(), p.z() / radii.z());
296 double k0 = pr.norm();
297 double k1 =
Point3D(p.x() / (radii.x() * radii.x()),
298 p.y() / (radii.y() * radii.y()),
299 p.z() / (radii.z() * radii.z())).norm();
302 return -std::min({radii.x(), radii.y(), radii.z()});
304 return k0 * (k0 - 1.0) / k1;
334 double px = std::abs(p.x());
335 double pz = std::abs(p.z());
337 double d_hex = std::max(px + pz * 0.577350269189626, pz * 1.154700538379252) - radius;
339 return std::max(d_hex, std::abs(p.y()) - height * 0.5);
366 return p.cross(axis).norm() - radius;
393 [[nodiscard]]
inline double wedge(
const Point3D& p,
double w,
double h,
double d) {
395 double d_box = q.cwiseMax(0.0).norm()
396 + std::min(std::max({q.x(), q.y(), q.z()}), 0.0);
398 double d_cut = (p.x() - p.z()) * 0.707106781186548;
399 return std::max(d_box, d_cut);
453 return std::max(sdf_2d, std::abs(p.z()) - half_height);
507 [[nodiscard]]
double cone(
const Point3D& p,
double angle_rad,
double height);
531 const Point3D& c,
double height);
552 [[nodiscard]]
double link(
const Point3D& p,
double length,
double major_r,
double minor_r);
576 const Vector3D& axis,
double angle_rad);
foundation::Vector3D Vector3D
双精度三维向量(重新导出)
foundation::Point3D Point3D
双精度三维点(重新导出)
double link(const Point3D &p, double length, double major_r, double minor_r)
双环链接体的 SDF(非内联实现)
double cone(const Point3D &p, double angle_rad, double height)
圆锥台的 SDF(非内联实现)
double infinite_cylinder(const Point3D &p, const Vector3D &axis, double radius)
无限长圆柱的 SDF
double ellipsoid(const Point3D &p, const Point3D &radii)
椭球体的 SDF(有界梯度近似)
double hex_prism(const Point3D &p, double radius, double height)
正六棱柱的 SDF
double extrusion(const Point3D &, double sdf_2d)
二维 SDF 沿 Z 轴的无限挤出
double capsule(const Point3D &p, const Point3D &a, const Point3D &b, double radius)
胶囊体的 SDF
double triangular_prism(const Point3D &p, const Point3D &a, const Point3D &b, const Point3D &c, double height)
三角棱柱的 SDF(非内联实现)
double box(const Point3D &p, const Point3D &half_extents)
轴对齐立方体的 SDF
double infinite_cone(const Point3D &p, const Point3D &apex, const Vector3D &axis, double angle_rad)
无限圆锥的 SDF(非内联实现)
double cylinder(const Point3D &p, double radius, double height)
带平端盖的圆柱体 SDF
double torus(const Point3D &p, double major_radius, double minor_radius)
圆环面的 SDF
double round_box(const Point3D &p, const Point3D &half_extents, double r)
圆角立方体的 SDF
double revolution(const Point3D &, double sdf_2d, double)
二维轮廓绕 Y 轴的旋转体 SDF
double wedge(const Point3D &p, double w, double h, double d)
楔形体的 SDF
double extrusion_bounded(const Point3D &p, double sdf_2d, double half_height)
二维 SDF 的有限长度挤出
double sphere(const Point3D &p, double radius)
球体的 SDF
double plane(const Point3D &p, const Vector3D &normal, double offset)
平面的 SDF