Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 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.  
  18. void equation(const Point& a, const Point& b, const Point& c, Eq& eq) {
  19.     Point v1 = b - a;
  20.     Point v2 = c - a;
  21.  
  22.     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 };
  23.  
  24.     eq.a = norm.x;
  25.     eq.b = norm.y;
  26.     eq.c = norm.z;
  27.     eq.d = -(norm.x * a.x + norm.y * a.y + norm.z * a.z);
  28. }
  29.  
  30. float dist(const Point& p, const Eq& eq) {
  31.     float ans = (eq.a * p.x + eq.b * p.y + eq.c * p.z + eq.d) / sqrt(eq.a * eq.a + eq.b * eq.b + eq.c * eq.c);
  32.     return ans;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement