Sketcher Ellipse: porting to DeriVector2
Sketcher Ellipse: porting tangent-line to DeriVector2 Replacing a ton of unreadable, sage generated math code with easy-to-manage C++ code. Sketcher Ellipse: porting internal align-t to DeriVector2 Sketcher Ellipse: small math refactor; const members Moving the repeating code computing deriv+value of major radius to a method of GCS::Ellipse. Marking several methods of DeriVector2 as const member functions. Sketcher Ellipse: porting arc angle rules to DeriVector2 Just porting. Probably a complete remake of the concept is worth... Angles can be calculated explicitly, there's no need to load the solver. I see no benefits whatsoever on using the solver to keep track of angle values. Sketcher Ellipse: porting equality to DeriVector2
This commit is contained in:
parent
43e8b30846
commit
8660d9a914
File diff suppressed because it is too large
Load Diff
|
@ -349,7 +349,8 @@ namespace GCS
|
|||
class ConstraintEllipseTangentLine : public Constraint
|
||||
{
|
||||
private:
|
||||
inline double* p1x() { return pvec[0]; }
|
||||
/*tbd
|
||||
* inline double* p1x() { return pvec[0]; }
|
||||
inline double* p1y() { return pvec[1]; }
|
||||
inline double* p2x() { return pvec[2]; }
|
||||
inline double* p2y() { return pvec[3]; }
|
||||
|
@ -357,10 +358,13 @@ namespace GCS
|
|||
inline double* cy() { return pvec[5]; }
|
||||
inline double* f1x() { return pvec[6]; }
|
||||
inline double* f1y() { return pvec[7]; }
|
||||
inline double* rmin() { return pvec[8]; }
|
||||
inline double* rmin() { return pvec[8]; }*/
|
||||
Line l;
|
||||
Ellipse e;
|
||||
void ReconstructGeomPointers(); //writes pointers in pvec to the parameters of crv1, crv2 and poa
|
||||
void errorgrad(double* err, double* grad, double *param); //error and gradient combined. Values are returned through pointers.
|
||||
public:
|
||||
ConstraintEllipseTangentLine(Line &l, Ellipse &e);
|
||||
ConstraintEllipseTangentLine(Line &l, ArcOfEllipse &a);
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
@ -369,42 +373,28 @@ namespace GCS
|
|||
|
||||
class ConstraintInternalAlignmentPoint2Ellipse : public Constraint
|
||||
{
|
||||
private:
|
||||
inline double* p1x() { return pvec[0]; }
|
||||
inline double* p1y() { return pvec[1]; }
|
||||
inline double* cx() { return pvec[2]; }
|
||||
inline double* cy() { return pvec[3]; }
|
||||
inline double* f1x() { return pvec[4]; }
|
||||
inline double* f1y() { return pvec[5]; }
|
||||
inline double* rmin() { return pvec[6]; }
|
||||
public:
|
||||
ConstraintInternalAlignmentPoint2Ellipse(Ellipse &e, Point &p1, InternalAlignmentType alignmentType);
|
||||
ConstraintInternalAlignmentPoint2Ellipse(ArcOfEllipse &e, Point &p1, InternalAlignmentType alignmentType);
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
virtual double grad(double *);
|
||||
private:
|
||||
void errorgrad(double* err, double* grad, double *param); //error and gradient combined. Values are returned through pointers.
|
||||
void ReconstructGeomPointers(); //writes pointers in pvec to the parameters of crv1, crv2 and poa
|
||||
Ellipse e;
|
||||
Point p;
|
||||
InternalAlignmentType AlignmentType;
|
||||
};
|
||||
|
||||
class ConstraintEqualMajorAxesEllipse : public Constraint
|
||||
{
|
||||
private:
|
||||
inline double* e1cx() { return pvec[0]; }
|
||||
inline double* e1cy() { return pvec[1]; }
|
||||
inline double* e1f1x() { return pvec[2]; }
|
||||
inline double* e1f1y() { return pvec[3]; }
|
||||
inline double* e1rmin() { return pvec[4]; }
|
||||
inline double* e2cx() { return pvec[5]; }
|
||||
inline double* e2cy() { return pvec[6]; }
|
||||
inline double* e2f1x() { return pvec[7]; }
|
||||
inline double* e2f1y() { return pvec[8]; }
|
||||
inline double* e2rmin() { return pvec[9]; }
|
||||
private:
|
||||
Ellipse e1, e2;
|
||||
void ReconstructGeomPointers(); //writes pointers in pvec to the parameters of crv1, crv2 and poa
|
||||
void errorgrad(double* err, double* grad, double *param); //error and gradient combined. Values are returned through pointers.
|
||||
public:
|
||||
ConstraintEqualMajorAxesEllipse(Ellipse &e1, Ellipse &e2);
|
||||
ConstraintEqualMajorAxesEllipse(ArcOfEllipse &a1, Ellipse &e2);
|
||||
ConstraintEqualMajorAxesEllipse(ArcOfEllipse &a1, ArcOfEllipse &a2);
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
@ -415,14 +405,11 @@ namespace GCS
|
|||
class ConstraintEllipticalArcRangeToEndPoints : public Constraint
|
||||
{
|
||||
private:
|
||||
inline double* p1x() { return pvec[0]; }
|
||||
inline double* p1y() { return pvec[1]; }
|
||||
inline double* angle() { return pvec[2]; }
|
||||
inline double* cx() { return pvec[3]; }
|
||||
inline double* cy() { return pvec[4]; }
|
||||
inline double* f1x() { return pvec[5]; }
|
||||
inline double* f1y() { return pvec[6]; }
|
||||
inline double* rmin() { return pvec[7]; }
|
||||
void errorgrad(double* err, double* grad, double *param); //error and gradient combined. Values are returned through pointers.
|
||||
void ReconstructGeomPointers(); //writes pointers in pvec to the parameters of crv1, crv2 and poa
|
||||
Ellipse e;
|
||||
Point p;
|
||||
public:
|
||||
ConstraintEllipticalArcRangeToEndPoints(Point &p, ArcOfEllipse &a, double *angle_t);
|
||||
virtual ConstraintType getTypeId();
|
||||
|
|
|
@ -39,7 +39,7 @@ DeriVector2::DeriVector2(const Point &p, double *derivparam)
|
|||
dy = 1.0;
|
||||
}
|
||||
|
||||
double DeriVector2::length(double &dlength)
|
||||
double DeriVector2::length(double &dlength) const
|
||||
{
|
||||
double l = length();
|
||||
if(l==0){
|
||||
|
@ -51,7 +51,7 @@ double DeriVector2::length(double &dlength)
|
|||
}
|
||||
}
|
||||
|
||||
DeriVector2 DeriVector2::getNormalized()
|
||||
DeriVector2 DeriVector2::getNormalized() const
|
||||
{
|
||||
double l=length();
|
||||
if(l==0.0) {
|
||||
|
@ -71,7 +71,7 @@ DeriVector2 DeriVector2::getNormalized()
|
|||
}
|
||||
}
|
||||
|
||||
double DeriVector2::scalarProd(const DeriVector2 &v2, double *dprd)
|
||||
double DeriVector2::scalarProd(const DeriVector2 &v2, double *dprd) const
|
||||
{
|
||||
if (dprd) {
|
||||
*dprd = dx*v2.x + x*v2.dx + dy*v2.y + y*v2.dy;
|
||||
|
@ -79,7 +79,8 @@ double DeriVector2::scalarProd(const DeriVector2 &v2, double *dprd)
|
|||
return x*v2.x + y*v2.y;
|
||||
}
|
||||
|
||||
DeriVector2 DeriVector2::divD(double val, double dval){
|
||||
DeriVector2 DeriVector2::divD(double val, double dval) const
|
||||
{
|
||||
return DeriVector2(x/val,y/val,
|
||||
dx/val - x*dval/(val*val),
|
||||
dy/val - y*dval/(val*val)
|
||||
|
@ -178,6 +179,32 @@ Arc* Arc::Copy()
|
|||
|
||||
|
||||
//--------------ellipse
|
||||
|
||||
//this function is exposed to allow reusing pre-filled derivectors in constraints code
|
||||
double Ellipse::getRadMaj(const DeriVector2 ¢er, const DeriVector2 &f1, double b, double db, double &ret_dRadMaj)
|
||||
{
|
||||
double cf, dcf;
|
||||
cf = f1.subtr(center).length(dcf);
|
||||
DeriVector2 hack (b, cf,
|
||||
db, dcf);//hack = a nonsense vector to calculate major radius with derivatives, useful just because the calculation formula is the same as vector length formula
|
||||
return hack.length(ret_dRadMaj);
|
||||
}
|
||||
|
||||
//returns major radius. The derivative by derivparam is returned into ret_dRadMaj argument.
|
||||
double Ellipse::getRadMaj(double *derivparam, double &ret_dRadMaj)
|
||||
{
|
||||
DeriVector2 c(center, derivparam);
|
||||
DeriVector2 f1(focus1, derivparam);
|
||||
return getRadMaj(c, f1, *radmin, radmin==derivparam ? 1.0 : 0.0, ret_dRadMaj);
|
||||
}
|
||||
|
||||
//returns the major radius (plain value, no derivatives)
|
||||
double Ellipse::getRadMaj()
|
||||
{
|
||||
double dradmaj;//dummy
|
||||
return getRadMaj(0,dradmaj);
|
||||
}
|
||||
|
||||
DeriVector2 Ellipse::CalculateNormal(Point &p, double* derivparam)
|
||||
{
|
||||
//fill some vectors in
|
||||
|
|
|
@ -59,27 +59,27 @@ namespace GCS
|
|||
double x, dx;
|
||||
double y, dy;
|
||||
|
||||
double length() {return sqrt(x*x + y*y);}
|
||||
double length(double &dlength); //returns length and writes length deriv into the dlength argument.
|
||||
double length() const {return sqrt(x*x + y*y);}
|
||||
double length(double &dlength) const; //returns length and writes length deriv into the dlength argument.
|
||||
|
||||
|
||||
//unlike other vectors in FreeCAD, this normalization creates a new vector instead of modifying existing one.
|
||||
DeriVector2 getNormalized(); //returns zero vector if the original is zero.
|
||||
double scalarProd(const DeriVector2 &v2, double* dprd=0);//calculates scalar product of two vectors and returns the result. The derivative of the result is written into argument dprd.
|
||||
DeriVector2 sum(const DeriVector2 &v2){//adds two vectors and returns result
|
||||
DeriVector2 getNormalized() const; //returns zero vector if the original is zero.
|
||||
double scalarProd(const DeriVector2 &v2, double* dprd=0) const;//calculates scalar product of two vectors and returns the result. The derivative of the result is written into argument dprd.
|
||||
DeriVector2 sum(const DeriVector2 &v2) const {//adds two vectors and returns result
|
||||
return DeriVector2(x + v2.x, y + v2.y,
|
||||
dx + v2.dx, dy + v2.dy);}
|
||||
DeriVector2 subtr(const DeriVector2 &v2){//subtracts two vectors and returns result
|
||||
DeriVector2 subtr(const DeriVector2 &v2) const {//subtracts two vectors and returns result
|
||||
return DeriVector2(x - v2.x, y - v2.y,
|
||||
dx - v2.dx, dy - v2.dy);}
|
||||
DeriVector2 mult(double val){
|
||||
DeriVector2 mult(double val) const {
|
||||
return DeriVector2(x*val, y*val, dx*val, dy*val);}//multiplies the vector by a number. Derivatives are scaled.
|
||||
DeriVector2 multD(double val, double dval){//multiply vector by a variable with a derivative.
|
||||
DeriVector2 multD(double val, double dval) const {//multiply vector by a variable with a derivative.
|
||||
return DeriVector2(x*val, y*val, dx*val+x*dval, dy*val+y*dval);}
|
||||
DeriVector2 divD(double val, double dval);//divide vector by a variable with a derivative
|
||||
DeriVector2 rotate90ccw(){return DeriVector2(-y,x,-dy,dx);}
|
||||
DeriVector2 rotate90cw(){return DeriVector2(y,-x,dy,-dx);}
|
||||
DeriVector2 linCombi(double m1, const DeriVector2 &v2, double m2){//linear combination of two vectors
|
||||
DeriVector2 divD(double val, double dval) const;//divide vector by a variable with a derivative
|
||||
DeriVector2 rotate90ccw() const {return DeriVector2(-y,x,-dy,dx);}
|
||||
DeriVector2 rotate90cw() const {return DeriVector2(y,-x,dy,-dx);}
|
||||
DeriVector2 linCombi(double m1, const DeriVector2 &v2, double m2) const {//linear combination of two vectors
|
||||
return DeriVector2(x*m1 + v2.x*m2, y*m1 + v2.y*m2,
|
||||
dx*m1 + v2.dx*m2, dy*m1 + v2.dy*m2);}
|
||||
|
||||
|
@ -156,6 +156,9 @@ namespace GCS
|
|||
Point center;
|
||||
Point focus1;
|
||||
double *radmin;
|
||||
double getRadMaj(const DeriVector2 ¢er, const DeriVector2 &f1, double b, double db, double &ret_dRadMaj);
|
||||
double getRadMaj(double* derivparam, double &ret_dRadMaj);
|
||||
double getRadMaj();
|
||||
DeriVector2 CalculateNormal(Point &p, double* derivparam = 0);
|
||||
virtual int PushOwnParams(VEC_pD &pvec);
|
||||
virtual void ReconstructOnNewPvec (VEC_pD &pvec, int &cnt);
|
||||
|
|
Loading…
Reference in New Issue
Block a user