C语言编程立体像对的空间前方交会(分别已知两像片的像对坐标x1,x2和其方位元素和内方位元素)的严密共线方程计算窗口程序
时间: 2023-06-19 08:04:31 浏览: 137
前方交会_立体像对_摄影测量前方交会_前方交会C++_前方交会C++_
5星 · 资源好评率100%
以下是计算C语言编程立体像对的空间前方交会的严密共线方程的窗口程序:
```c
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <conio.h>
#include <graphics.h>
#define PI 3.14159265358979323846
void main()
{
float x1, y1, x2, y2, Xs1, Ys1, f1, k1, Xs2, Ys2, f2, k2, L1, L2, M1, M2, N1, N2, X, Y, Z;
int gd = DETECT, gm;
printf("Enter the coordinates of image 1 (x1, y1): ");
scanf("%f %f", &x1, &y1);
printf("Enter the coordinates of image 2 (x2, y2): ");
scanf("%f %f", &x2, &y2);
printf("Enter the orientation elements of image 1 (Xs1, Ys1, f1, k1): ");
scanf("%f %f %f %f", &Xs1, &Ys1, &f1, &k1);
printf("Enter the orientation elements of image 2 (Xs2, Ys2, f2, k2): ");
scanf("%f %f %f %f", &Xs2, &Ys2, &f2, &k2);
// Convert orientation elements from degrees to radians
f1 = f1 * PI / 180;
k1 = k1 * PI / 180;
f2 = f2 * PI / 180;
k2 = k2 * PI / 180;
// Compute the direction cosines of the ray in image 1
L1 = cos(f1) * cos(k1);
M1 = cos(f1) * sin(k1);
N1 = sin(f1);
// Compute the direction cosines of the ray in image 2
L2 = cos(f2) * cos(k2);
M2 = cos(f2) * sin(k2);
N2 = sin(f2);
// Compute the coefficients of the linear equation system
float a[3][3] = {
{L1 - L2, M1 - M2, N1 - N2},
{Xs2 - Xs1, Ys2 - Ys1, -1},
{x2 - x1, y2 - y1, 0}
};
float b[3] = {Xs2 - Xs1, y1 - Ys1, x1 - Xs1};
// Solve the linear equation system
float det = a[0][0] * (a[1][1] * a[2][2] - a[1][2] * a[2][1]) -
a[0][1] * (a[1][0] * a[2][2] - a[1][2] * a[2][0]) +
a[0][2] * (a[1][0] * a[2][1] - a[1][1] * a[2][0]);
if (det == 0) {
printf("The linear equation system does not have a unique solution.\n");
return;
}
float x = (b[0] * (a[1][1] * a[2][2] - a[1][2] * a[2][1]) -
b[1] * (a[0][1] * a[2][2] - a[0][2] * a[2][1]) +
b[2] * (a[0][1] * a[1][2] - a[0][2] * a[1][1])) / det;
float y = (b[1] * (a[0][0] * a[2][2] - a[0][2] * a[2][0]) -
b[0] * (a[1][0] * a[2][2] - a[1][2] * a[2][0]) +
b[2] * (a[0][0] * a[1][2] - a[0][2] * a[1][0])) / det;
float z = (b[2] * (a[0][0] * a[1][1] - a[0][1] * a[1][0]) -
b[0] * (a[1][1] * a[2][2] - a[1][2] * a[2][1]) +
b[1] * (a[0][1] * a[2][2] - a[0][2] * a[2][1])) / det;
// Compute the 3D coordinates of the intersection point
X = x + Xs1;
Y = y + Ys1;
Z = z + f1;
// Display the result
printf("The 3D coordinates of the intersection point are:\n");
printf("X = %f, Y = %f, Z = %f\n", X, Y, Z);
// Draw the 3D point on the screen
initgraph(&gd, &gm, "");
int x_screen = X * 10 + 320;
int y_screen = Y * 10 + 240;
circle(x_screen, y_screen, 5);
getch();
closegraph();
}
```
该程序会提示用户输入图像1和图像2的像对坐标和方位元素,然后计算它们的严密共线方程,并求出它们的交点的三维坐标。最后,程序会在屏幕上绘制该点的图像。
阅读全文