• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Aug 25th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. // C++ implementation​​​​​​‌​​​‌​​​‌​​‌‌​‌​‌​‌​​​​​​ below
2. #include "math.h"
3.
4. struct Vector
5. {
6.     // Extend this struct as you see fit
7.
8.     Vector(double inX, double inY, double inZ)
9.     : x(inX), y(inY), z(inZ) {}
10.
11.     Vector() : Vector(0.0, 0.0, 0.0) {}
12.
13.     double x;
14.     double y;
15.     double z;
16. };
17.
18. typedef Vector Point;
19.
20. struct Plane
21. {
22.     Point origin;
23.     Vector dirrection1;
24.     Vector dirrection2;
25. };
26.
27. // Vector norm() {
28.
29. // }
30.
31. //vec - falling vector
32. bool GetReflected(const Vector& vec, const Plane& plane, Vector *reflected )
33. {
34.     // length of vec
35.     //sqrt(vec.x * vec.x + vec.y * vec.x + vec.z);
36.     //plane 1, plane 2
37.     Vector n;
38.     n.x = plane.dirrection1.y * plane.dirrection2.z  - plane.dirrection1.z * plane.dirrection2.y;
39.     n.y = plane.dirrection1.z * plane.dirrection2.x  - plane.dirrection1.x * plane.dirrection2.z;
40.     n.z = plane.dirrection1.x * plane.dirrection2.y  - plane.dirrection1.y * plane.dirrection2.x;
41.
42.     Vector n2;
43.     n2.x = 2*n.x;
44.     n2.y = 2*n.y;
45.     n2.z = 2*n.z;
46.
47.     //I x N
48.     Vector in;
49.
50.     in.x = vec.y * n2.z - vec.z * n2.y;
51.     in.y = vec.z * n2.x - vec.x * n2.z;
52.     in.z = vec.x * n2.y - vec.y * n2.x;
53.
54.     //2 * (I x N)
55.
56.     Vector R;
57.     R.x = vec.x - in.x;
58.     R.y = vec.y - in.y;
59.     R.z = vec.z - in.z;
60.
61.
62.     if (abs(R.x) == abs(vec.x)) return true;
63.
64.
65.     return false;
66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top