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 };
- }
- };
- void equation(const Point& a, const Point& b, const Point& c, float& A, float& B, float& C, float& D) {
- 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 };
- A = norm.x;
- B = norm.y;
- C = norm.z;
- D = -(norm.x * a.x + norm.y * a.y + norm.z * a.z);
- }
- float dist(const Point& p, float A, float B, float C, float D) {
- float ans = (A * p.x + B * p.y + C * p.z + D) / sqrt(A * A + B * B + C * C);
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement