Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- double distance(double pointx, double pointy, double pointz, double tAx, double tAy, double tAz, double tBx, double tBy, double tBz, double tCx, double tCy, double tCz){
- double A, B, C, D, distance;
- A = tAy*(tBz-tCz)+tBy*(tCz-tAz)+tCy*(tAz-tBz);
- B = tAx*(tCz-tBz)+tBx*(tAz-tCz)+tCx*(tBz-tAz);
- C = tAx*(tBy-tCy)+tBx*(tCy-tAy)+tCx*(tAy-tBy);
- D = -tAx * A-tAy * B-tAz * C;
- if(A == 0 && B == 0 && C == 0){
- printf("Error");
- return 0;
- }
- distance = fabs(A * pointx + B * pointy + C * pointz + D) / sqrt(pow(A, 2) + pow(B, 2) + pow(C, 2));
- return distance;
- }
- int main(void){
- double p1, p2, p3, p4, p5, p6, p7, p8, p9;
- printf("Enter the coordinates of 3 pointsn");
- printf("Point 1:");
- scanf("%lf %lf %lf", &p1, &p2, &p3);
- printf("Point 2:");
- scanf("%lf %lf %lf", &p4, &p5, &p6);
- printf("Point 3:");
- scanf("%lf %lf %lf", &p7, &p8, &p9);
- double A1x, A1y, A1z, B1x, B1y, B1z, C1x, C1y, C1z;
- double A2x, A2y, A2z, B2x, B2y, B2z, C2x, C2y, C2z;
- double A3x, A3y, A3z, B3x, B3y, B3z, C3x, C3y, C3z;
- printf("Enter the coordinates of the three trianglesn");
- printf("First trianglen");
- printf("Point A:");
- scanf("%lf %lf %lf", &A1x, &A1y, &A1z);
- printf("Point B:");
- scanf("%lf %lf %lf", &B1x, &B1y, &B1z);
- printf("Point C:");
- scanf("%lf %lf %lf", &C1x, &C1y, &C1z);
- printf("Second trianglen");
- printf("Point A:");
- scanf("%lf %lf %lf", &A2x, &A2y, &A2z);
- printf("Point B:");
- scanf("%lf %lf %lf", &B2x, &B2y, &B2z);
- printf("Point C:");
- scanf("%lf %lf %lf", &C2x, &C2y, &C2z);
- printf("Third trianglen");
- printf("Point A:");
- scanf("%lf %lf %lf", &A3x, &A3y, &A3z);
- printf("Point B:");
- scanf("%lf %lf %lf", &B3x, &B3y, &B3z);
- printf("Point C:");
- scanf("%lf %lf %lf", &C3x, &C3y, &C3z);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement