Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. struct Point {
  2.     float x;
  3.     float y;
  4.     float z;
  5.  
  6.     Point operator - (const Point& other) const {
  7.         return { x - other.x, y - other.y, z - other.z };
  8.     }
  9. };
  10.  
  11. void equation(const Point& a, const Point& b, const Point& c, float& A, float& B, float& C, float& D) {
  12.     Point v1 = b - a;
  13.     Point v2 = c - a;
  14.  
  15.     Point norm = { v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x };
  16.  
  17.     A = norm.x;
  18.     B = norm.y;
  19.     C = norm.z;
  20.     D = -(norm.x * a.x + norm.y * a.y + norm.z * a.z);
  21. }
  22.  
  23. float dist(const Point& p, float A, float B, float C, float D) {
  24.     float ans = (A * p.x + B * p.y + C * p.z + D) / sqrt(A * A + B * B + C * C);
  25.     return ans;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement