class point { private: // 最好不要省略private double x0,y0,f,X,Y,Z,Xs,Ys,Zs,omega,kappa,alpha; public: point(double x0,double y0,double f,double X,double Y,double Z,double Xs,double Ys,double Zs,double omega,double kappa,double alpha);//构造函数 void XYZtoxy(); }; #include "stdafx.h" #include "Time.h" #include<iostream> using namespace std; point::point(double x0,double y0,double f,double X,double Y,double Z,double Xs,double Ys,double Zs,double omega,double kappa,double alpha) { cout<<"请输入内方位元素x0,y0,f:"; cin>>x0>>y0>>f; cout<<"请输入地面点坐标X,Y,Z:"; cin>>X>>Y>>Z; cout<<"请输入外方位元素Xs,Ys,Zs,alpha,omega,kappa:"; cin>>Xs>>Ys>>Zs>>omega>>alpha>>kappa; /* x0=x0; y0=y0; f=f; X=X; Y=Y; Z=Z; Xs=Xs; Ys=Ys; Zs=Zs; omega=omega; phi=phi; kappa=kappa; */ } void point::XYZtoxy() { double a1,a2,a3,b1,b2,b3,c1,c2,c3; a1=cos(alpha)*cos(kappa)-sin(alpha)*sin(omega)*sin(kappa); a2=-cos(alpha)*sin(kappa)-sin(alpha)*sin(omega)*cos(kappa); a3=-sin(alpha)*cos(omega); b1=cos(omega)*sin(kappa); b2=cos(omega)*cos(kappa); b3=-sin(omega); c1=sin(alpha)*cos(kappa)+cos(alpha)*sin(omega)*sin(kappa); c2=-sin(alpha)*sin(kappa)+cos(alpha)*sin(omega)*cos(kappa); c3=cos(alpha)*cos(omega); double x=(a1*(X-Xs)+b1*(Y-Ys)+c1*(Z-Zs))/(a3*(X-Xs)+b3*(Y-Ys)+c3*(Z-Zs))*(-f); double y=(a2*(X-Xs)+b2*(Y-Ys)+c2*(Z-Zs))/(a3*(X-Xs)+b3*(Y-Ys)+c3*(Z-Zs))*(-f); cout<<"像点坐标为:("<<x<<","<<y<<")"<<endl; } #include "stdafx.h" #include "Time.h" #include<iostream> using namespace std; int _tmain(int argc,_TCHAR*argv[]) { point P1; P1.XYZtoxy(); return 0; } 这段代码报错,请查明原因并改正
时间: 2023-06-15 20:06:30 浏览: 112
这段代码的报错可能是因为没有包含必要的头文件,例如在point类中使用了cos和sin函数,需要包含math.h头文件。另外,_tmain函数应该改为int main()。
以下是修改后的代码:
```
#include <iostream>
#include <math.h>
using namespace std;
class point {
private:
double x0, y0, f, X, Y, Z, Xs, Ys, Zs, omega, kappa, alpha;
public:
point(double x0, double y0, double f, double X, double Y, double Z, double Xs, double Ys, double Zs, double omega, double kappa, double alpha);
void XYZtoxy();
};
point::point(double x0, double y0, double f, double X, double Y, double Z, double Xs, double Ys, double Zs, double omega, double kappa, double alpha) {
cout << "请输入内方位元素x0,y0,f:";
cin >> this->x0 >> this->y0 >> this->f;
cout << "请输入地面点坐标X,Y,Z:";
cin >> this->X >> this->Y >> this->Z;
cout << "请输入外方位元素Xs,Ys,Zs,alpha,omega,kappa:";
cin >> this->Xs >> this->Ys >> this->Zs >> this->omega >> this->alpha >> this->kappa;
}
void point::XYZtoxy() {
double a1, a2, a3, b1, b2, b3, c1, c2, c3;
a1 = cos(alpha) * cos(kappa) - sin(alpha) * sin(omega) * sin(kappa);
a2 = -cos(alpha) * sin(kappa) - sin(alpha) * sin(omega) * cos(kappa);
a3 = -sin(alpha) * cos(omega);
b1 = cos(omega) * sin(kappa);
b2 = cos(omega) * cos(kappa);
b3 = -sin(omega);
c1 = sin(alpha) * cos(kappa) + cos(alpha) * sin(omega) * sin(kappa);
c2 = -sin(alpha) * sin(kappa) + cos(alpha) * sin(omega) * cos(kappa);
c3 = cos(alpha) * cos(omega);
double x = (a1 * (X - Xs) + b1 * (Y - Ys) + c1 * (Z - Zs)) / (a3 * (X - Xs) + b3 * (Y - Ys) + c3 * (Z - Zs)) * (-f);
double y = (a2 * (X - Xs) + b2 * (Y - Ys) + c2 * (Z - Zs)) / (a3 * (X - Xs) + b3 * (Y - Ys) + c3 * (Z - Zs)) * (-f);
cout << "像点坐标为:(" << x << "," << y << ")" << endl;
}
int main() {
point P1(0, 0, 0, 1000, 1000, 500, 10, 10, 10, 30, 40, 50);
P1.XYZtoxy();
return 0;
}
```
阅读全文