📄 cylinder.cpp
字号:
#if !defined(__cylinder_cpp)
#define __cylinder_cpp
//Difinition of cylinder class
#include <math.h>
#pragma hdrstop
#include "cylinder.h"
////Construcor and destructor
cylinder::cylinder(){
Radius = 100.0;
isHorizontal=true ;
};
cylinder::~cylinder(){
};
inline void cylinder::SetRadius(double r ){ Radius=r; };
inline double cylinder::GetRadius() {return(Radius);};
inline double cylinder::ZA(double a){
return (Radius-sqrt((Radius+a)*(Radius-a)));
};
inline double cylinder::gradA(double a){
return (a/sqrt((Radius+a)*(Radius-a)));
};
inline double cylinder::gradAA(double a){
return (Radius*Radius/((Radius+a)*(Radius-a))/sqrt((Radius+a)*(Radius-a)));
};
inline double cylinder::GetZ( double x, double y){
if (isHorizontal) {
return ZA(y);
}else{
return ZA(x);
};
//z=0 ,when x=y=0.
};
inline vector cylinder::GetPosition( double x, double y){
return ( vector( x, y, GetZ(x,y) ) );
};
inline double cylinder::gradX(double x, double y){
if (isHorizontal) {
return 0.;
}else{
return gradA(x);
};
};
inline double cylinder::gradY(double x, double y){
if (isHorizontal) {
return gradA(y);
}else{
return 0.;
};
};
inline double cylinder::gradXX(double x, double y){
if (isHorizontal) {
return 0.;
}else{
return gradAA(x);
};
};
inline double cylinder::gradYY(double x, double y){
if (isHorizontal) {
return gradAA(y);
}else{
return 0.;
};
};
// This is the normal vector of surface on the point(x,y).
// This is toward the inside of cylinder.
// This.length is 1.
vector cylinder::NormalVector ( double x, double y){
return ( vector( -gradX(x,y), -gradY(x,y), 1).normalize() ); //OK 980520
};
vector cylinder::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 cylinder::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 cylinder::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 cylinder::NoGradientVector(double x,double y){
return( NormalVector(x,y)%GradientVector(x,y) );
};
vector cylinder::NoGradientVector(vector position){
return( NormalVector(position)%GradientVector(position) );
};
int cylinder::WriteFaceName(ofstream& fout){
fout << "(Face name is : cylinder);" << endl;
return(1);
};
int cylinder::WriteParameters(ofstream& fout){
if (isHorizontal==true) {
fout << "(Y-AXIS);" << endl;
}else{
fout << "(X-AXIS);" << endl;
};
fout << "(Radius[mm] is :" << Radius <<");" << endl;
return(1);
};
void cylinder::SetParameter(TStringList *str)
{
for (int i=0; i<str->Count; i++){
AnsiString temp;
temp = "Radius";
if (str->Names[i]==temp){
Radius = str->Values[str->Names[i]].ToDouble();
};
temp = "isHorizontal";
if (str->Names[i]==temp){
isHorizontal = str->Values[str->Names[i]].ToInt();
};
};
face::SetFaceParameter(str);
};
void cylinder::GetParameter(TStringList *str)
{
str->Add(AnsiString("---cylinder parameter(s)---"));
str->Add(AnsiString("FaceType=cylinder"));
str->Add(AnsiString("Radius=")+ Radius);
str->Add(AnsiString("isHorizontal=")+ AnsiString((int)isHorizontal) );
if(isHorizontal==true){
str->Add(AnsiString("//cylinder axis \/\/ Y-axis"));
}else{
str->Add(AnsiString("//cylinder axis \/\/ X-axis"));
};
face::GetFaceParameter(str);
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -