Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4.  
  5. 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){
  6. double A, B, C, D, distance;
  7. A = tAy*(tBz-tCz)+tBy*(tCz-tAz)+tCy*(tAz-tBz);
  8. B = tAx*(tCz-tBz)+tBx*(tAz-tCz)+tCx*(tBz-tAz);
  9. C = tAx*(tBy-tCy)+tBx*(tCy-tAy)+tCx*(tAy-tBy);
  10. D = -tAx * A-tAy * B-tAz * C;
  11.  
  12. if(A == 0 && B == 0 && C == 0){
  13. printf("Error");
  14. return 0;
  15. }
  16.  
  17. distance = fabs(A * pointx + B * pointy + C * pointz + D) / sqrt(pow(A, 2) + pow(B, 2) + pow(C, 2));
  18. return distance;
  19. }
  20.  
  21. int main(void){
  22. double p1, p2, p3, p4, p5, p6, p7, p8, p9;
  23. printf("Enter the coordinates of 3 pointsn");
  24. printf("Point 1:");
  25. scanf("%lf %lf %lf", &p1, &p2, &p3);
  26. printf("Point 2:");
  27. scanf("%lf %lf %lf", &p4, &p5, &p6);
  28. printf("Point 3:");
  29. scanf("%lf %lf %lf", &p7, &p8, &p9);
  30. double A1x, A1y, A1z, B1x, B1y, B1z, C1x, C1y, C1z;
  31. double A2x, A2y, A2z, B2x, B2y, B2z, C2x, C2y, C2z;
  32. double A3x, A3y, A3z, B3x, B3y, B3z, C3x, C3y, C3z;
  33.  
  34. printf("Enter the coordinates of the three trianglesn");
  35. printf("First trianglen");
  36. printf("Point A:");
  37. scanf("%lf %lf %lf", &A1x, &A1y, &A1z);
  38. printf("Point B:");
  39. scanf("%lf %lf %lf", &B1x, &B1y, &B1z);
  40. printf("Point C:");
  41. scanf("%lf %lf %lf", &C1x, &C1y, &C1z);
  42. printf("Second trianglen");
  43. printf("Point A:");
  44. scanf("%lf %lf %lf", &A2x, &A2y, &A2z);
  45. printf("Point B:");
  46. scanf("%lf %lf %lf", &B2x, &B2y, &B2z);
  47. printf("Point C:");
  48. scanf("%lf %lf %lf", &C2x, &C2y, &C2z);
  49. printf("Third trianglen");
  50. printf("Point A:");
  51. scanf("%lf %lf %lf", &A3x, &A3y, &A3z);
  52. printf("Point B:");
  53. scanf("%lf %lf %lf", &B3x, &B3y, &B3z);
  54. printf("Point C:");
  55. scanf("%lf %lf %lf", &C3x, &C3y, &C3z);
  56.  
  57. getch();
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement