mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-19 13:40:49 +03:00
0023706: Cannot project point on curve
1. Approximation of derivative (by Taylor-series and by three points). 2. Some methods (Degree(), GetType(), D0(), D3(), DN()) are added. 3. Getting of subInterval's boundaries. 4. Algorithm for checking if 1st derivative is equal to zero is amended. 5. Cases are controlled when extrema or Project point do not exist. 6. GetNormal() function for gp_Vec2d was added. 7. Computing of Value, D0, D1, D2 and D3 for offset curves was changed. 8. Limitation of tolerance for derivative computing was added. 9. Methods for computing trihedron in singularity point are added. 10. Test tests/bugs/moddata_3/bug23706 is added. 11. Restriction on the LastParameter for visualization of 3-D curves. Calling PlotCurve(...) function for last interval. 12. LProp package is modified for tangent computing in singularity point (LProp_CLProps, LProp_SLProps). 13. Added test cases for issue. Deleting bad test cases for this fix
This commit is contained in:
@@ -188,7 +188,19 @@ is
|
||||
-- Warning : It used only for C2 aproximation
|
||||
returns Boolean
|
||||
is private;
|
||||
|
||||
|
||||
RotateTrihedron(me;
|
||||
Tangent : out Vec from gp;
|
||||
Normal : out Vec from gp;
|
||||
BiNormal : out Vec from gp;
|
||||
NewTangent : in Vec from gp)
|
||||
---Purpose: revolves the trihedron (which is determined
|
||||
-- of given "Tangent", "Normal" and "BiNormal" vectors)
|
||||
-- to coincide "Tangent" and "NewTangent" axes.
|
||||
returns Boolean from Standard
|
||||
is private;
|
||||
|
||||
|
||||
fields
|
||||
P : Pnt from gp;
|
||||
mySngl : HArray1OfReal from TColStd;
|
||||
|
@@ -31,8 +31,11 @@
|
||||
#include <TCollection_CompareOfReal.hxx>
|
||||
#include <TColgp_SequenceOfPnt2d.hxx>
|
||||
|
||||
#define NullTol 1.e-10
|
||||
#define MaxSingular 1.e-5
|
||||
static const Standard_Real NullTol = 1.e-10;
|
||||
static const Standard_Real MaxSingular = 1.e-5;
|
||||
|
||||
static const Standard_Integer maxDerivOrder = 3;
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : FDeriv
|
||||
@@ -59,6 +62,30 @@ static gp_Vec DDeriv(const gp_Vec& F, const gp_Vec& DF, const gp_Vec& D2F)
|
||||
return Result;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CosAngle
|
||||
//purpose : Return a cosine between vectors theV1 and theV2.
|
||||
//=======================================================================
|
||||
static Standard_Real CosAngle(const gp_Vec& theV1, const gp_Vec& theV2)
|
||||
{
|
||||
const Standard_Real aTol = gp::Resolution();
|
||||
|
||||
const Standard_Real m1 = theV1.Magnitude(), m2 = theV2.Magnitude();
|
||||
if((m1 <= aTol) || (m2 <= aTol)) //Vectors are codirectional
|
||||
return 1.0;
|
||||
|
||||
Standard_Real aCAng = theV1.Dot(theV2)/(m1*m2);
|
||||
|
||||
if(aCAng > 1.0)
|
||||
aCAng = 1.0;
|
||||
|
||||
if(aCAng < -1.0)
|
||||
aCAng = -1.0;
|
||||
|
||||
|
||||
return aCAng;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GeomFill_Frenet
|
||||
//purpose :
|
||||
@@ -314,36 +341,205 @@ Handle(GeomFill_TrihedronLaw) GeomFill_Frenet::Copy() const
|
||||
else isSngl = Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RotateTrihedron
|
||||
//purpose : This function revolves the trihedron (which is determined of
|
||||
// given "Tangent", "Normal" and "BiNormal" vectors)
|
||||
// to coincide "Tangent" and "NewTangent" axes.
|
||||
//=======================================================================
|
||||
Standard_Boolean
|
||||
GeomFill_Frenet::RotateTrihedron( gp_Vec& Tangent,
|
||||
gp_Vec& Normal,
|
||||
gp_Vec& BiNormal,
|
||||
const gp_Vec& NewTangent) const
|
||||
{
|
||||
const Standard_Real anInfCOS = cos(Precision::Angular()); //0.99999995
|
||||
const Standard_Real aTol = gp::Resolution();
|
||||
|
||||
gp_Vec anAxis = Tangent.Crossed(NewTangent);
|
||||
const Standard_Real NT = anAxis.Magnitude();
|
||||
if(NT <= aTol)
|
||||
//No rotation required
|
||||
return Standard_True;
|
||||
else
|
||||
anAxis /= NT; //Normalization
|
||||
|
||||
const Standard_Real aPx = anAxis.X(), aPy = anAxis.Y(), aPz = anAxis.Z();
|
||||
const Standard_Real aCAng = CosAngle(Tangent,NewTangent); //cosine
|
||||
|
||||
const Standard_Real anAddCAng = 1.0 - aCAng;
|
||||
const Standard_Real aSAng = sqrt(1.0 - aCAng*aCAng); //sine
|
||||
|
||||
//According to rotate direction, sine of rotation angle might be
|
||||
//positive or negative.
|
||||
//We can research to choose necessary sign. But I think, it is more
|
||||
//effectively, to rotate "Tangent" vector in both direction. After that
|
||||
//we can choose necessary rotation direction in depend of results.
|
||||
|
||||
const gp_Vec aV11(anAddCAng*aPx*aPx+aCAng, anAddCAng*aPx*aPy-aPz*aSAng, anAddCAng*aPx*aPz+aPy*aSAng);
|
||||
const gp_Vec aV12(anAddCAng*aPx*aPx+aCAng, anAddCAng*aPx*aPy+aPz*aSAng, anAddCAng*aPx*aPz-aPy*aSAng);
|
||||
const gp_Vec aV21(anAddCAng*aPx*aPy+aPz*aSAng, anAddCAng*aPy*aPy+aCAng, anAddCAng*aPy*aPz-aPx*aSAng);
|
||||
const gp_Vec aV22(anAddCAng*aPx*aPy-aPz*aSAng, anAddCAng*aPy*aPy+aCAng, anAddCAng*aPy*aPz+aPx*aSAng);
|
||||
const gp_Vec aV31(anAddCAng*aPx*aPz-aPy*aSAng, anAddCAng*aPy*aPz+aPx*aSAng, anAddCAng*aPz*aPz+aCAng);
|
||||
const gp_Vec aV32(anAddCAng*aPx*aPz+aPy*aSAng, anAddCAng*aPy*aPz-aPx*aSAng, anAddCAng*aPz*aPz+aCAng);
|
||||
|
||||
gp_Vec aT1(Tangent.Dot(aV11), Tangent.Dot(aV21), Tangent.Dot(aV31));
|
||||
gp_Vec aT2(Tangent.Dot(aV12), Tangent.Dot(aV22), Tangent.Dot(aV32));
|
||||
|
||||
if(CosAngle(aT1,NewTangent) >= CosAngle(aT2,NewTangent))
|
||||
{
|
||||
Tangent = aT1;
|
||||
Normal = gp_Vec(Normal.Dot(aV11), Normal.Dot(aV21), Normal.Dot(aV31));
|
||||
BiNormal = gp_Vec(BiNormal.Dot(aV11), BiNormal.Dot(aV21), BiNormal.Dot(aV31));
|
||||
}
|
||||
else
|
||||
{
|
||||
Tangent = aT2;
|
||||
Normal = gp_Vec(Normal.Dot(aV12), Normal.Dot(aV22), Normal.Dot(aV32));
|
||||
BiNormal = gp_Vec(BiNormal.Dot(aV12), BiNormal.Dot(aV22), BiNormal.Dot(aV32));
|
||||
}
|
||||
|
||||
return CosAngle(Tangent,NewTangent) >= anInfCOS;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : D0
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean GeomFill_Frenet::D0(const Standard_Real Param,
|
||||
Standard_Boolean GeomFill_Frenet::D0(const Standard_Real theParam,
|
||||
gp_Vec& Tangent,
|
||||
gp_Vec& Normal,
|
||||
gp_Vec& BiNormal)
|
||||
{
|
||||
const Standard_Real aTol = gp::Resolution();
|
||||
|
||||
Standard_Real norm;
|
||||
Standard_Integer Index;
|
||||
Standard_Real Delta = 0.;
|
||||
if(IsSingular(Param, Index))
|
||||
if (SingularD0(Param, Index, Tangent, Normal, BiNormal, Delta))
|
||||
if(IsSingular(theParam, Index))
|
||||
if (SingularD0(theParam, Index, Tangent, Normal, BiNormal, Delta))
|
||||
return Standard_True;
|
||||
|
||||
Standard_Real theParam = Param + Delta;
|
||||
myTrimmed->D2(theParam, P, Tangent, BiNormal);
|
||||
Tangent.Normalize();
|
||||
BiNormal = Tangent.Crossed(BiNormal);
|
||||
norm = BiNormal.Magnitude();
|
||||
if (norm <= gp::Resolution()) {
|
||||
gp_Ax2 Axe (gp_Pnt(0,0,0), Tangent);
|
||||
BiNormal.SetXYZ(Axe.YDirection().XYZ());
|
||||
}
|
||||
else BiNormal.Normalize();
|
||||
Standard_Real aParam = theParam + Delta;
|
||||
myTrimmed->D2(aParam, P, Tangent, BiNormal);
|
||||
|
||||
Normal = BiNormal;
|
||||
Normal.Cross(Tangent);
|
||||
const Standard_Real DivisionFactor = 1.e-3;
|
||||
const Standard_Real anUinfium = myTrimmed->FirstParameter();
|
||||
const Standard_Real anUsupremum = myTrimmed->LastParameter();
|
||||
const Standard_Real aDelta = (anUsupremum - anUinfium)*DivisionFactor;
|
||||
Standard_Real Ndu = Tangent.Magnitude();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
if(Ndu <= aTol)
|
||||
{
|
||||
gp_Vec aTn;
|
||||
//Derivative is approximated by Taylor-series
|
||||
|
||||
Standard_Integer anIndex = 1; //Derivative order
|
||||
Standard_Boolean isDeriveFound = Standard_False;
|
||||
|
||||
do
|
||||
{
|
||||
aTn = myTrimmed->DN(theParam,++anIndex);
|
||||
Ndu = aTn.Magnitude();
|
||||
isDeriveFound = Ndu > aTol;
|
||||
}
|
||||
while(!isDeriveFound && anIndex < maxDerivOrder);
|
||||
|
||||
if(isDeriveFound)
|
||||
{
|
||||
Standard_Real u;
|
||||
|
||||
if(theParam-anUinfium < aDelta)
|
||||
u = theParam+aDelta;
|
||||
else
|
||||
u = theParam-aDelta;
|
||||
|
||||
gp_Pnt P1, P2;
|
||||
myTrimmed->D0(Min(theParam, u),P1);
|
||||
myTrimmed->D0(Max(theParam, u),P2);
|
||||
|
||||
gp_Vec V1(P1,P2);
|
||||
Standard_Real aDirFactor = aTn.Dot(V1);
|
||||
|
||||
if(aDirFactor < 0.0)
|
||||
aTn = -aTn;
|
||||
}//if(IsDeriveFound)
|
||||
else
|
||||
{
|
||||
//Derivative is approximated by three points
|
||||
|
||||
gp_Pnt Ptemp(0.0,0.0,0.0); //(0,0,0)-coordinate
|
||||
gp_Pnt P1, P2, P3;
|
||||
Standard_Boolean IsParameterGrown;
|
||||
|
||||
if(theParam-anUinfium < 2*aDelta)
|
||||
{
|
||||
myTrimmed->D0(theParam,P1);
|
||||
myTrimmed->D0(theParam+aDelta,P2);
|
||||
myTrimmed->D0(theParam+2*aDelta,P3);
|
||||
IsParameterGrown = Standard_True;
|
||||
}
|
||||
else
|
||||
{
|
||||
myTrimmed->D0(theParam-2*aDelta,P1);
|
||||
myTrimmed->D0(theParam-aDelta,P2);
|
||||
myTrimmed->D0(theParam,P3);
|
||||
IsParameterGrown = Standard_False;
|
||||
}
|
||||
|
||||
gp_Vec V1(Ptemp,P1), V2(Ptemp,P2), V3(Ptemp,P3);
|
||||
|
||||
if(IsParameterGrown)
|
||||
aTn=-3*V1+4*V2-V3;
|
||||
else
|
||||
aTn=V1-4*V2+3*V3;
|
||||
}//else of "if(IsDeriveFound)" condition
|
||||
Ndu = aTn.Magnitude();
|
||||
gp_Pnt Pt = P;
|
||||
Standard_Real dPar = 10.0*aDelta;
|
||||
|
||||
//Recursive calling is used for determine of trihedron for
|
||||
//point, which is near to given.
|
||||
if(theParam-anUinfium < dPar)
|
||||
{
|
||||
if(D0(aParam+dPar,Tangent,Normal,BiNormal) == Standard_False)
|
||||
return Standard_False;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(D0(aParam-dPar,Tangent,Normal,BiNormal) == Standard_False)
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
P = Pt;
|
||||
|
||||
if(RotateTrihedron(Tangent,Normal,BiNormal,aTn) == Standard_False)
|
||||
{
|
||||
#ifdef DEB
|
||||
cout << "Cannot coincide two tangents." << endl;
|
||||
#endif
|
||||
return Standard_False;
|
||||
}
|
||||
}//if(Ndu <= aTol)
|
||||
else
|
||||
{
|
||||
Tangent = Tangent/Ndu;
|
||||
BiNormal = Tangent.Crossed(BiNormal);
|
||||
norm = BiNormal.Magnitude();
|
||||
if (norm <= gp::Resolution())
|
||||
{
|
||||
gp_Ax2 Axe (gp_Pnt(0,0,0), Tangent);
|
||||
BiNormal.SetXYZ(Axe.YDirection().XYZ());
|
||||
}
|
||||
else
|
||||
BiNormal.Normalize();
|
||||
|
||||
Normal = BiNormal;
|
||||
Normal.Cross(Tangent);
|
||||
}
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
@@ -99,6 +99,27 @@ is
|
||||
--- Purpose : Raised if the continuity of the current interval
|
||||
-- is not C2.
|
||||
is redefined static;
|
||||
|
||||
D3 (me; U : Real; P : out Pnt from gp; V1, V2, V3 : out Vec from gp)
|
||||
--- Purpose :
|
||||
-- Returns the point P of parameter U, the first, the second
|
||||
-- and the third derivative.
|
||||
raises
|
||||
DomainError from Standard
|
||||
--- Purpose : Raised if the continuity of the current interval
|
||||
-- is not C1.
|
||||
|
||||
is redefined static;
|
||||
|
||||
DN (me; U : Real; N : Integer) returns Vec from gp
|
||||
--- Purpose :
|
||||
-- The returned vector gives the value of the derivative for the
|
||||
-- order of derivation N.
|
||||
raises
|
||||
OutOfRange from Standard
|
||||
--- Purpose : Raised if N < 1.
|
||||
is redefined static;
|
||||
|
||||
|
||||
Resolution(me; R3d : Real) returns Real
|
||||
---Purpose : Returns the parametric resolution corresponding
|
||||
|
@@ -21,6 +21,7 @@
|
||||
|
||||
|
||||
#include <GeomFill_SnglrFunc.ixx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
#include <Precision.hxx>
|
||||
|
||||
GeomFill_SnglrFunc::GeomFill_SnglrFunc(const Handle(Adaptor3d_HCurve)& HC) :
|
||||
@@ -121,6 +122,45 @@ void GeomFill_SnglrFunc::SetRatio(const Standard_Real Ratio)
|
||||
V2 *= ratio;
|
||||
}
|
||||
|
||||
void GeomFill_SnglrFunc::D3(const Standard_Real U,gp_Pnt& P,gp_Vec& V1,gp_Vec& V2,gp_Vec& V3) const
|
||||
{
|
||||
gp_Vec DC, D2C, D3C, D4C, D5C;
|
||||
myHCurve->D3(U, P, DC, D2C, D3C);
|
||||
D4C = myHCurve->DN(U, 4);
|
||||
D5C = myHCurve->DN(U, 5);
|
||||
P = gp_Pnt(DC.Crossed(D2C).XYZ()).ChangeCoord()*ratio;
|
||||
V1 = DC.Crossed(D3C)*ratio;
|
||||
V2 = (D2C.Crossed(D3C) + DC.Crossed(D4C))*ratio;
|
||||
V3 = (DC.Crossed(D5C) + D2C.Crossed(D4C)*2)*ratio;
|
||||
}
|
||||
|
||||
gp_Vec GeomFill_SnglrFunc::DN(const Standard_Real U,const Standard_Integer N) const
|
||||
{
|
||||
Standard_RangeError_Raise_if (N < 1, "Exception: Geom2d_OffsetCurve::DN(). N<1.");
|
||||
|
||||
gp_Vec D1C, D2C, D3C;
|
||||
gp_Pnt C;
|
||||
|
||||
switch(N)
|
||||
{
|
||||
case 1:
|
||||
D1(U,C,D1C);
|
||||
return D1C;
|
||||
case 2:
|
||||
D2(U,C,D1C,D2C);
|
||||
return D2C;
|
||||
case 3:
|
||||
D3(U,C,D1C,D2C,D3C);
|
||||
return D3C;
|
||||
default:
|
||||
Standard_NotImplemented::Raise("Exception: Derivative order is greater than 3. "
|
||||
"Cannot compute of derivative.");
|
||||
}
|
||||
|
||||
return gp_Vec();
|
||||
|
||||
}
|
||||
|
||||
Standard_Real GeomFill_SnglrFunc::Resolution(const Standard_Real R3D) const
|
||||
{
|
||||
return Precision::Parametric(R3D);
|
||||
|
Reference in New Issue
Block a user