试用期员工
- UID
- 665
- 积分
- 258
- 金币
-
- 活跃
-
- 阅读权限
- 30
- 注册时间
- 2006-9-18
- 最后登录
- 1970-1-1
|
- class XhmTransformation3D
- {
- public:
- double matrix11, matrix12, matrix13, matrix14;
- double matrix21, matrix22, matrix23, matrix24;
- double matrix31, matrix32, matrix33, matrix34;
- double matrix41, matrix42, matrix43, matrix44;
- XhmTransformation3D() {
- matrix11 = 1.0, matrix12 = 0.0, matrix13 = 0.0, matrix14 = 0.0;
- matrix21 = 0.0, matrix22 = 1.0, matrix23 = 0.0, matrix24 = 0.0;
- matrix31 = 0.0, matrix32 = 0.0, matrix33 = 1.0, matrix34 = 0.0;
- matrix41 = 0.0, matrix42 = 0.0, matrix43 = 0.0, matrix44 = 1.0;
- }
- };
- class XhmPoint2D
- {
- public:
- double X, Y; // XY坐标
- //默认初始化
- XhmPoint2D() {
- X = 0.0, Y = 0.0;
- }
- //输入初始化
- XhmPoint2D(double x, double y) {
- X = x, Y = y;
- }
- //计算点到点的距离
- double DistanceToPoint(XhmPoint2D p){
- return (sqrt(pow(X - p.X,2) + pow(Y - p.Y,2) ));
- }
- //移动点
- double Move(double xmove, double ymove){
- X += xmove, Y += ymove;
- }
- //通过两个点的中点定义点
- void SetFromMidpoint(XhmPoint2D p1, XhmPoint2D p2) {
- X = p1.X + (p2.X - p1.X) * 0.5;
- Y = p1.Y + (p2.Y - p1.Y) * 0.5;
- }
- };
- class XhmPoint3D
- {
- public:
- double X, Y, Z; // XYZ坐标
- //默认初始化
- XhmPoint3D() {
- X = 0.0, Y = 0.0, Z = 0.0;
- }
- //输入初始化
- XhmPoint3D(double x, double y, double z) {
- X = x, Y = y, Z = z;
- }
- //计算点到点的距离
- double DistanceToPoint(XhmPoint3D p) {
- return (sqrt(pow(X - p.X, 2) + pow(Y - p.Y, 2) + pow(Z - p.Z, 2)));
- }
- //计算点到点的距离
- double Move(double xmove, double ymove, double zmove) {
- X += xmove, Y += ymove, Z += zmove;
- }
- //通过两个点的中点定义点
- void SetFromMidpoint(XhmPoint3D p1, XhmPoint3D p2) {
- X = p1.X + (p2.X - p1.X) * 0.5;
- Y = p1.Y + (p2.Y - p1.Y) * 0.5;
- Z = p1.Z + (p2.Z - p1.Z) * 0.5;
- }
- //点矩阵变换
- void SetFromMidpoint(XhmTransformation3D tra) {
- double proj = X * tra.matrix14 + Y * tra.matrix24 + Z * tra.matrix34 + tra.matrix44;
- if (proj <= 1.0E-15 and proj >= -1.0E-15) {
- proj = 1.0;
- }
- X = (X * tra.matrix11 + Y * tra.matrix21 + Z * tra.matrix31 + tra.matrix41) / proj;
- Y = (X * tra.matrix12 + Y * tra.matrix22 + Z * tra.matrix32 + tra.matrix42) / proj;
- Z = (X * tra.matrix13 + Y * tra.matrix23 + Z * tra.matrix33 + tra.matrix43) / proj;
- }
- };
- class XhmVector2D
- {
- public:
- double X, Y; // XY坐标
- //默认初始化
- XhmVector2D() {
- X = 0.0, Y = 0.0;
- }
- //输入初始化
- XhmVector2D(double x, double y) {
- X = x, Y = y;
- }
- //向量相加
- void Add(XhmVector2D vec) {
- X += vec.X, Y += vec.Y;
- }
- //向量相减
- void Subtract(XhmVector2D vec) {
- X -= vec.X, Y -= vec.Y;
- }
- //向量积
- double DotProduct(XhmVector2D vec) {
- return (X * vec.X + Y * vec.Y);
- }
- //缩放矢量
- void BlankProduct(double sc) {
- X *= sc, Y *= sc;
- }
- //向量比较
- bool CompareVector(XhmVector2D vec, double tolerance) {
- double xx = sqrt((X - vec.X) * (X - vec.X) + (Y - vec.Y) * (Y - vec.Y));
- return (xx < tolerance) ? true : false;
- }
- //获取向量偏X还是偏Y
- string LargestComponentAxis(XhmVector2D vec, double tolerance) {
- return (X < Y) ? "Y" : "X";
- }
- //获取向量长度
- double Length() {
- return (sqrt(X * X + Y * Y));
- }
- //旋转矢量,angle为弧度
- void Rotate(double angle) {
- X = cos(angle) * X - sin(angle) * Y;
- Y = sin(angle) * X + cos(angle) * Y;
- }
- //向量上的标量分量
- double ScalarComponentOnVector(XhmVector2D vec) {
- double L1 = vec.Length();
- return (L1 < 1.0E-15) ? 0 : (X * vec.X + Y * vec.Y) / L1;
- }
- //通过两点定义向量
- void SetFromPoints(XhmPoint2D p1, XhmPoint2D p2) {
- X = p2.X - p1.X;
- Y = p2.Y - p1.Y;
- }
- //通过VEC向量定义向量
- void SetFromVector(XhmVector2D vec) {
- X = vec.X;
- Y = vec.Y;
- }
- //通过VEC向量相减定义向量
- void SetFromVectorDifference(XhmVector2D vec1, XhmVector2D vec2) {
- X = vec1.X - vec2.X;
- Y = vec1.Y - vec2.Y;
- }
- //通过VEC向量相加定义向量
- void SetFromVectorSum(XhmVector2D vec1, XhmVector2D vec2) {
- X = vec1.X + vec2.X;
- Y = vec1.Y + vec2.Y;
- }
- //设置为单位向量,长度为1
- void SetToUnitVector() {
- double l = Length();
- if (l >= 1.0E-15)
- {
- X = X / l;
- Y = Y / l;
- }
- }
- //设置向量长度
- void SetLength(double l) {
- SetToUnitVector();
- BlankProduct(l);
- }
- };
复制代码
|
|