You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

91 lines
1.5 KiB

#include<string>
#include<iostream>
#include<cmath>
#include <iomanip>
using namespace std;
const double eps=1e-6;
#define Equal(a,b) ((fabs(a-b)<eps)?true:false)
struct P{
double x,y,z; //坐标
double dx,dy,dz; //方向
bool isend; //是否为端点
int type; //0卡箍 1未确定分支点 2已确定分支点 3连接器
int ref; //指向其代表的相应数据类型标号
bool operator <(P B)const{
if(!Equal(x,B.x))return x<B.x;
if(!Equal(y,B.y))return y<B.y;
if(!Equal(z,B.z))return z<B.z;
return false;
}
bool operator ==(P B)const{
return Equal(x,B.x)&&Equal(y,B.y)&&Equal(z,B.z);
}
bool operator !=(P B)const{
return !(Equal(x,B.x)&&Equal(y,B.y)&&Equal(z,B.z));
}
void set(int i,double v){
if(i==0)x=v;
else if(i==1)y=v;
else if(i==2)z=v;
}
const double get(int i){
if(i==0)return x;
else if(i==1)return y;
else if(i==2)return z;
return 0;
}
void reverse(){
dx=-dx;
dy=-dy;
dz=-dz;
}
P(double x1,double y1,double z1){
x=x1;y=y1;z=z1;
dx=0;dy=dz=0;
isend=0;
type=ref=0;
}
P(){
x=y=z=0;
dx=0;dy=dz=0;
isend=0;
type=ref=0;
}
P operator -(P B)const{
return P(x-B.x,y-B.y,z-B.z);
}
P operator +(P B)const{
return P(x+B.x,y+B.y,z+B.z);
}
P operator *(double p)const{
return P(x*p,y*p,z*p);
}
P operator /(double p)const{
return P(x/p,y/p,z/p);
}
void print(string s){
cout<<s<<setprecision(10)<<" : "<<x<<" "<<y<<" "<<z<<endl;
return;
}
//设置方向
void setDir(P& dir){
dx=dir.x;
dy=dir.y;
dz=dir.z;
}
};
P dirP(P &A){
P B;
B.x=A.dx;
B.y=A.dy;
B.z=A.dz;
return B;
}