Browse Source

end case of sdf

master
gjj 4 months ago
parent
commit
fc199701d0
  1. 6
      include/line.hpp
  2. 16
      include/solid.hpp

6
include/line.hpp

@ -289,6 +289,8 @@ public:
real h = std::clamp(AP.dot(AB) / AB.dot(AB), 0., 1.); real h = std::clamp(AP.dot(AB) / AB.dot(AB), 0., 1.);
return {h, (AP - AB * h).norm()}; return {h, (AP - AB * h).norm()};
} }
bool isEndParm(real t) { return t < EPS || t > _points.size() - 1 - EPS; }
}; };
class HelixLine : public ILine { class HelixLine : public ILine {
@ -307,6 +309,10 @@ private:
real startTheta; // 轴线起始时在螺旋投影(圆)上的参数 real startTheta; // 轴线起始时在螺旋投影(圆)上的参数
}; };
class SingleLine : public ILine {
public:
};
class PolynomialLine : public ILine { class PolynomialLine : public ILine {
public: public:
Vec3 eval(real param) override { return {}; }; Vec3 eval(real param) override { return {}; };

16
include/solid.hpp

@ -19,11 +19,9 @@ inline Vec2 get2DRepOf3DPt(const Vec3 &pt3D, const Vec3 &u, const Vec3 &v, const
Vec3 OP = pt3D - localO; Vec3 OP = pt3D - localO;
return {OP.dot(u), OP.dot(v)}; return {OP.dot(u), OP.dot(v)};
} }
inline Vec2 get2DRepOf3DDir(const Vec3 &dir, const Vec3 &u, const Vec3 &v) { inline Vec2 get2DRepOf3DDir(const Vec3 &dir, const Vec3 &u, const Vec3 &v) {
return Vec2{dir.dot(u), dir.dot(v)}.normalize(); return Vec2{dir.dot(u), dir.dot(v)}.normalize();
} }
class IExtrudedSolid : public ISolid { class IExtrudedSolid : public ISolid {
public: public:
std::vector<Polyline> _profiles; // TODO: may be replaced by const ref to profile std::vector<Polyline> _profiles; // TODO: may be replaced by const ref to profile
@ -51,7 +49,6 @@ private:
std::vector<std::vector<CircularArc<Vec2>>> _localArcs2d; std::vector<std::vector<CircularArc<Vec2>>> _localArcs2d;
// Pt2Array _localCircleCenter2D; // Pt2Array _localCircleCenter2D;
// Pt2Array _localInCircleDir; // Pt2Array _localInCircleDir;
public: public:
ExtrudedSolidPolyline(std::vector<Polyline> profiles, Polyline axis, real rScale) ExtrudedSolidPolyline(std::vector<Polyline> profiles, Polyline axis, real rScale)
: IExtrudedSolid(std::move(profiles), rScale), _axis(std::move(axis)) { : IExtrudedSolid(std::move(profiles), rScale), _axis(std::move(axis)) {
@ -90,11 +87,17 @@ public:
ClosestDescOnSeg closestDescToAxis = _axis.getClosestParam(p); ClosestDescOnSeg closestDescToAxis = _axis.getClosestParam(p);
// TNB coordinate system // TNB coordinate system
auto t = closestDescToAxis.t; auto t = closestDescToAxis.t;
Vec3 Q = _axis.eval(t); // closest point on axis
Vec3 QP = p - Q;
Vec3 T = _axis.der1(t).normalize(); Vec3 T = _axis.der1(t).normalize();
if (_axis.isEndParm(t) && fabs(QP.dot(T)) > EPS) {
// project p to the plane passing through Q and perpendicular to T
Vec3 projP = p + T * (-QP.dot(T));
}
Vec3 N = _axis.der2(t).normalize(); Vec3 N = _axis.der2(t).normalize();
Vec3 B = T.cross(N); Vec3 B = T.cross(N);
Vec3 Q = _axis.eval(t);
Vec3 QP = p - Q;
auto p2D = get2DRepOf3DPt(QP, N, B, Q); auto p2D = get2DRepOf3DPt(QP, N, B, Q);
// PMC // PMC
PtBoundaryRelation ptProfileRelation = Inside; PtBoundaryRelation ptProfileRelation = Inside;
@ -109,6 +112,7 @@ public:
break; break;
} }
} }
// distance // distance
ClosestDescOnSeg closestDescToProfile{}; ClosestDescOnSeg closestDescToProfile{};
for (int i = 0; i < _localArcs2d.size(); ++i) { for (int i = 0; i < _localArcs2d.size(); ++i) {
@ -122,7 +126,7 @@ public:
} }
private: private:
/** /** 低于2Dprofile的内外部判定
* in + in = out * in + in = out
* in + out = in * in + out = in
* out + in = in * out + in = in

Loading…
Cancel
Save