⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xafs.cpp

📁 曲面加工程序源码,用C++编写的加工曲线曲面的程序
💻 CPP
字号:
#if !defined(__xafs_cpp)
#define __xafs_cpp

//Difinition of xafs class    19990318

#include <math.h>
#pragma hdrstop

#include "xafs.h"

////Construcor and destructor
xafs::xafs(){

   cx=100.019998; //[mm]
   cy=2.; //[mm]
   cz=2.; //[mm]

   dx=0.; //[mm]
   dy=0.; //[mm]
   dz=-2.; //[mm]

};

xafs::~xafs(){

};
//equations for calcuration

/*inline double xafs::A( double x, double y){

        double a = 1 - x*x/cx/cx - y*y/cy/cy;
        return (a>0)?sqrt(a):0;
};*/

inline double xafs::MirrorZ(double x,double y){

   double a = 1 - x*x/cx/cx - y*y/cy/cy;
   double A = (a>0)?sqrt(a):0;

   return cz*(1.-A);

};
inline double xafs::MirrorgradX(double x,double y){

   double a = 1 - x*x/cx/cx - y*y/cy/cy;
   return  (a>0)?(cz*x)/(cx*cx*sqrt(a)):0;

};
inline double xafs::MirrorgradY(double x,double y){

   double a = 1 - x*x/cx/cx - y*y/cy/cy;
   return  (a>0)?(cz*y)/(cy*cy*sqrt(a)):0;

};
inline double xafs::MirrorgradXX(double x,double y){

   double a = 1 - x*x/cx/cx - y*y/cy/cy;
   return  (a>0)?(cz*(cy*cy - y*y))/(sqrt(a)*(-(cy*cy*x*x) + cx*cx*(cy*cy - y*y))):0;

};
inline double xafs::MirrorgradYY(double x,double y){

   double a = 1 - x*x/cx/cx - y*y/cy/cy;
   return  (a>0)?(cz*(cx*cx - x*x))/(sqrt(a)*(-(cy*cy*x*x) + cx*cx*(cy*cy - y*y))):0;

};

inline double xafs::GetZ( double x, double y){

   double z;

   z=MirrorZ(x,y);

   return z;

   //z=0 ,when x=y=0.

};

inline vector xafs::GetPosition( double x, double y){
	return ( vector( x, y, GetZ(x,y) ) );
};

inline double xafs::gradX(double x, double y){

   double value;

   value = MirrorgradX(x,y);

   return value;

};

inline double xafs::gradY(double x, double y){

   double z;
   double value;

   double b;

   value = MirrorgradY(x,y);

   return value;

};

inline double xafs::gradXX(double x, double y){

   double value;
   value = MirrorgradXX(x,y);

   return value;

};

inline double xafs::gradYY(double x, double y){

   double value;

   value = MirrorgradYY(x,y);

   return value;
};

// This is the normal vector of surface on the point(x,y).
// This is toward the inside of xafs.
// This.length is 1.
vector xafs::NormalVector ( double x, double y){
	return ( vector( -gradX(x,y), -gradY(x,y), 1).normalize() );  //OK 980520
};
vector xafs::NormalVector ( vector position){
	return ( NormalVector( position.getX(), position.getY() ) );
};

////GradientVector////////////////////////////////////////////
// This is one of tangential vactors on the tangential plane.
// This is toward direction which has the largest gradient.
// This length is 1.
vector xafs::GradientVector(double x, double y){
	double gx = gradX( x,y);
	double gy = gradY( x,y);

	return ( vector( gx, gy, gx*gx+gy*gy ).normalize() );
};
vector xafs::GradientVector( vector position){
	return( GradientVector( position.getX(), position.getY() ) );
};

////NoGradientVector///////////////////////////////////////////
// This is one of tangential vactors on the tangential plane.
// This is toward direction which has no gradient.
//// This length will be 1,
//// and this Z-coordinate will be Zero.
vector xafs::NoGradientVector(double x,double y){
	return( NormalVector(x,y)%GradientVector(x,y) );
};
vector xafs::NoGradientVector(vector position){
	return( NormalVector(position)%GradientVector(position) );
};


int xafs::WriteFaceName(ofstream& fout){

	fout << "(Face name is : xafs);" << endl;
	return(1);
};
int xafs::WriteParameters(ofstream& fout){

	fout << "(cx[mm] is :" << cx <<");" << endl;
	fout << "(cy[mm] is :" << cy <<");" << endl;
	fout << "(cz[mm] is :" << cz <<");" << endl;

	fout << "(dx[mm] is :" << dx <<");" << endl;
	fout << "(dy[mm] is :" << dy <<");" << endl;
	fout << "(dz[mm] is :" << dz <<");" << endl;

	return(1);
};


void xafs::SetParameter(TStringList *str)
{
   for (int i=0; i<str->Count; i++){

         AnsiString temp;

         temp = "cx";
         if (str->Names[i]==temp){
              cx = str->Values[str->Names[i]].ToDouble();
         };
         temp = "cy";
         if (str->Names[i]==temp){
              cy = str->Values[str->Names[i]].ToDouble();
         };
         temp = "cz";
         if (str->Names[i]==temp){
              cz = str->Values[str->Names[i]].ToDouble();
         };

         temp = "dx";
         if (str->Names[i]==temp){
              dx = str->Values[str->Names[i]].ToDouble();
         };
         temp = "dy";
         if (str->Names[i]==temp){
              dy = str->Values[str->Names[i]].ToDouble();
         };
         temp = "dz";
         if (str->Names[i]==temp){
              dz = str->Values[str->Names[i]].ToDouble();
         };

   };
   face::SetFaceParameter(str);
};

void xafs::GetParameter(TStringList *str)
{

   str->Add(AnsiString("---xafs parameter(s)---"));
   str->Add(AnsiString("FaceType=xafs"));

   str->Add(AnsiString("---(x/cx)^2+(y/cy)^2+(z/cz)^2=1---"));

   str->Add(AnsiString("cx=")+ cx);
   str->Add(AnsiString("cy=")+ cy);
   str->Add(AnsiString("cz=")+ cz);

   str->Add(AnsiString("dx=")+ dx);
   str->Add(AnsiString("dy=")+ dy);
   str->Add(AnsiString("dz=")+ dz);

   face::GetFaceParameter(str);
};

#endif



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -