
So now we can plug in our numbers and solve our problem: The cross product of A(a 1,a 2,a 3)) and B(b 1,b 2,b 3)) is: To solve this, we can use the cross product: S = M x W. The sail has to be perpendicular to the mast, and also perpendicular to the wind. We have a vector for the direction of the mast M, going straight up (0,1,0), and the direction of the north-north-east wind W (1,0,2), and we want to find the direction the sail S should stick out in order to best catch the wind. So, what if we want to do this in 3D? Let's revisit our sailing ship. The left-facing cannons fire in the opposite direction, so we flip both signs to get: (-1,2). So, if the boat is facing along (2,1), the right-facing cannons fire towards (1,-2). Given that the boat is facing along the direction vector (2,1), in which directions do the cannons fire? This is easy in 2D: to rotate 90 degrees clockwise, just flip the two vector components, and then switch the sign of the second component. Let's say you have a boat that has cannons that fire to the left and right.

Vec2 guard_to_hero = normalize(hero_pos - guard_pos) įloat angle = acos( dot(guard_facing_n, guard_to_hero)) Cross Product Vec2 guard_facing_n = normalize(guard_facing)

Here is what this would like in Overgrowth using the C++ vector libraries I wrote (inspired by GLSL syntax). However, in a program, this is pretty simple.

I know this looks like a lot of work, and it is, because I'm doing it by hand. The angle between the center of the guard's vision and the hero is 72, so the guard does not see him!
