Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 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. struct Eq {
  12.     float a;
  13.     float b;
  14.     float c;
  15.     float d;
  16.  
  17.     Eq() {}
  18.  
  19.     Eq(float a, float b, float c, float d) : a(a), b(b), c(c), d(d) {}
  20.  
  21.     Eq(const Point& A, const Point& B, const Point& C) {
  22.         Point v1 = B - A;
  23.         Point v2 = C - A;
  24.  
  25.         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 };
  26.  
  27.         a = norm.x;
  28.         b = norm.y;
  29.         c = norm.z;
  30.         d = -(norm.x * A.x + norm.y * A.y + norm.z * A.z);
  31.     }
  32.  
  33.     float operator () (const Point& p) {
  34.         float ans = (a * p.x + b * p.y + c * p.z + d) / sqrt(a * a + b * b + c * c);
  35.         return ans;
  36.     }
  37. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement