Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C++ implementation below
- #include "math.h"
- struct Vector
- {
- // Extend this struct as you see fit
- Vector(double inX, double inY, double inZ)
- : x(inX), y(inY), z(inZ) {}
- Vector() : Vector(0.0, 0.0, 0.0) {}
- double x;
- double y;
- double z;
- };
- typedef Vector Point;
- struct Plane
- {
- Point origin;
- Vector dirrection1;
- Vector dirrection2;
- };
- // Vector norm() {
- // }
- //vec - falling vector
- bool GetReflected(const Vector& vec, const Plane& plane, Vector *reflected )
- {
- // length of vec
- //sqrt(vec.x * vec.x + vec.y * vec.x + vec.z);
- //plane 1, plane 2
- Vector n;
- n.x = plane.dirrection1.y * plane.dirrection2.z - plane.dirrection1.z * plane.dirrection2.y;
- n.y = plane.dirrection1.z * plane.dirrection2.x - plane.dirrection1.x * plane.dirrection2.z;
- n.z = plane.dirrection1.x * plane.dirrection2.y - plane.dirrection1.y * plane.dirrection2.x;
- Vector n2;
- n2.x = 2*n.x;
- n2.y = 2*n.y;
- n2.z = 2*n.z;
- //I x N
- Vector in;
- in.x = vec.y * n2.z - vec.z * n2.y;
- in.y = vec.z * n2.x - vec.x * n2.z;
- in.z = vec.x * n2.y - vec.y * n2.x;
- //2 * (I x N)
- Vector R;
- R.x = vec.x - in.x;
- R.y = vec.y - in.y;
- R.z = vec.z - in.z;
- if (abs(R.x) == abs(vec.x)) return true;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement