- UID
- 344993
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-11-2
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
class atomLine
{
public:
int kind;
double xb,yb,xe,ye,length;
virtual point(double len,double &x,double &y,double &angle)=0;
virtual void dump()=0;
atomLine(double xb,double yb,double xe,double ye,double length){
this->xb=xb;
this->yb=yb;
this->xe=xe;
this->ye=ye;
this->length=length;
}
};
class Line:public atomLine
{
public:
double ang;
point (double len,double &x,double &y,double &angle);
Line(double xb,double yb,double xe,double ye,double length):atomLine(xb,yb,xe,ye,length){
if (xe==xb)
ang=ye>yb?PI/2:-PI/2;
else
ang=atan2(ye-yb,xe-xb);
};
void dump(){ printf("Line---xb:%lf--yb:%lf--xe:%lf--ye:%lf--length::%lf\n",xb,yb,xe,ye,length);}
};
class Circle:public atomLine
{
public:
double xc,yc,R,RS;
point(double len,double &x,double &y,double &angle);
void dump(){ printf("Circle---xb:%lf--yb:%lf--xe:%lf--ye:%lf--length::%lf\n",xb,yb,xe,ye,length);
printf(" ---xc:%lf--yc:%lf--R:%lf--RS:%lf\n",xc,yc,R,RS);}
Circle(double xb,double yb,double xe,double ye,double length,
double xc,double yc,double R,double RS):atomLine(xb,yb,xe,ye,length){
this->xc=xc;
this->yc=yc;
this->R=R;
this->RS=RS;
}
};
class spiral :public atomLine
{
public:
double xc,yc,Rb,aza,A,RS;
point(double len,double &x,double &y,double &angle);
void dump(){ printf("spiral---length:%lf--xc:%lf--yc:%lf\n",length,xc,yc);
printf(" ---A:%lf--Rb:%lf--aza:%lf\n",A,Rb,aza);}
spiral(double length,double xc,double yc,
double Rb,double RS,double aza,double A):atomLine(0,0,0,0,length){
this->xc=xc;
this->yc=yc;
this->Rb=Rb;
this->aza=aza;
this->A=A;
this->RS=RS;
}
};
Line::point (double len,double &x,double &y,double &angle)
{
double temp=sqrt( (xe-xb)*(xe-xb)+(ye-yb)*(ye-yb) );
x=len*(xe-xb)/temp+xb;
y=len*(ye-yb)/temp+yb;
angle=ang;
return TRUE;
}
Circle::point(double len,double &x,double &y,double &angle)
{
double alpha=len*(-RS)/R;
double x1,y1,x11,y11;
x1=xb-xc;
y1=yb-yc;
y11=y1*cos(alpha)-x1*sin(alpha);
x11=y1*sin(alpha)+x1*cos(alpha);
x=x11+xc;
y=y11+yc;
x1=x-xc;
y1=y-yc;
if (x1==0)
angle=y1>0?PI/2:-PI/2;
else
angle=atan2(y1,x1);
if (RS>0)
angle+=PI/2;
else
angle-=PI/2;
return TRUE;
}
spiral::point(double len,double &x,double &y,double &angle)
{
if (A<=0.01)
return FALSE;
double len2;
if (Rb==0) //indicate MAXRADIUS
len2=0;
else
len2=A*A/Rb;
len2=fabs(len+len2);
double R;
if (len2==0)
angle=0;
else
{
R=A*A/len2;
angle=len2/R/2;
}
double x1,y1,x2,y2,t1,t2;
if (len2==0){
x1=0;
y1=0;
}
else {
x1=lbgX(A,len2);
y1=lbgY(A,len2);
}
double ls1;
if (Rb>=0) //Rb is big radius include 0 (Line)
ls1=1;
else
ls1=-1;
if (ls1*RS<0)
y1=-y1;
if (ls1>0&&RS>0) //big and right
angle=aza+angle;
else if (ls1<0&&RS>0) //small and right
angle=aza-angle+PI;
else if (ls1>0&&RS<0) //big and left
angle=aza-angle;
else if (ls1<0&&RS<0)
angle=aza+angle+PI;
t1=cos(aza);
t2=sin(aza);
x2=x1*t1-y1*t2;
y2=y1*t1+x1*t2;
x=xc+x2;
y=yc+y2;
return TRUE;
}
double funx(double l,double A)//A!=0
{
double t=l*l/2/A/A;
return cos(t);
}
double funy(double l,double A)
{
double t=l*l/2/A/A;
return sin(t);
}
double lbgX(double A,double b)
{
double h=b-0;//a=0
double T[MAX_STEPS],m1,m2;
T[0]=h*(funx(0,A)+funx(b,A))/2;
int k=1,i,j;
do {
m1=T[0];
////////////////////
T[0]=T[0]/2;
for (i=0;i<pow(2,k-1);i++)
T[0]+=h*funx( (2*i+1)*h/2,A )/2;
h/=2;
for (j=1;j<=k;j++)
{
m2=T[j];
T[j]=( pow(4,j)/( pow(4,j)-1 ) )*T[j-1]-m1/(pow(4,j)-1);
m1=m2;
}
if (fabs(T[k]-T[k-1])<EEE)
return T[k];
k++;
} while (k<MAX_STEPS);
return T[k-1];
}
double lbgY(double A,double b)
{
double h=b-0;//a=0
double T[MAX_STEPS],m1,m2;
T[0]=h*(funy(0,A)+funy(b,A))/2;
int k=1,i,j;
do {
m1=T[0];
////////////////////
T[0]=T[0]/2;
for (i=0;i<pow(2,k-1);i++)
T[0]+=h*funy( (2*i+1)*h/2,A )/2;
h/=2;
for (j=1;j<=k;j++)
{
m2=T[j];
T[j]=( pow(4,j)/( pow(4,j)-1 ) )*T[j-1]-m1/(pow(4,j)-1);
m1=m2;
}
if (fabs(T[k]-T[k-1])<EEE)
return T[k];
k++;
} while (k<MAX_STEPS);
return T[k-1];
} |
|