Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Point {
- float x;
- float y;
- float z;
- Point operator - (const Point& other) const {
- return { x - other.x, y - other.y, z - other.z };
- }
- };
- struct Eq {
- float a;
- float b;
- float c;
- float d;
- };
- void equation(const Point& a, const Point& b, const Point& c, Eq& eq) {
- Point v1 = b - a;
- Point v2 = c - a;
- 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 };
- eq.a = norm.x;
- eq.b = norm.y;
- eq.c = norm.z;
- eq.d = -(norm.x * a.x + norm.y * a.y + norm.z * a.z);
- }
- float dist(const Point& p, const Eq& eq) {
- 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);
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement