Hello,

I was scripting raycasts and everything was fine until I started printing the normals of the raycasts. When getting a normal of a flat part from the top the normal should be `0,1,0`

, but instead it is printing things like `0,1,4.3711388286738e-08`

out as the normal. When I get the top normal of the baseplate everything is fine so I don’t know what is causing the error.

`4.3711388286738e-08`

means `4.3711388286738 * 10^-8`

, which is extremely close to `0`

(about `0.0000000437`

). The reason why it’s not exactly `0`

is because of some small inaccuracy in calculating the normal.

Also why is the normal of a 45 degree rotated part not 0.5? It was something close to 0.7.

The value close to 0.7 is the sine of a 45 degree angle (or cosine, because sine and cosine are the same for 45 degrees).

The length of the normal vector is always 1 (possibly not exactly because of some inaccuracy, but almost). And the length of a 3d vector is `sqrt(x^2+y^2+z^2)`

. For example, if the part was rotated `45`

degrees around the x axis, its top normal would be `(0, sin(45), sin(45))`

. `sqrt(0^2+sin(45)^2+sin(45)^2)`

is `1`

. A vector with values `(0, 0.5, 0.5)`

would have the same direction, but its length would be `1/sqrt(2)`

.

How do I know when to use sin vs cos?

Perhaps this picture I found from google helps explain it. θ is the angle. Adjacent and opposite are the lengths of the sides that have a ninety degree angle between them. Adjacent refers to the side that forms θ with the longest side, which is called hypotenuse.

Edit: I apparently added the image incorrectly, so it didn’t show up.

Edit: Now I got it to appear.