I am developing the software to control a common fly's flight in Opensim simulator, although I am facing some troubles determining when the fly must maneuver to avoid hitting a wall.
- How do I get the point of collision between the fly and the wall?
- How do I know if I have to turn clockwise or counterclockwise?
I have access to the following data:
- Position of the center of wall in world coordinates.
- Two additional points representing the nearest end of the wall and the furthest, in local coordinates of the wall.
- Position of the fly in world coordinates.
- Vector representing the direction (force) of the fly in local coordinates.
- The difference, in radians, of the position of the local axis of the fly with regard to the global axis.
Example: a fly moving from left to right, and a wall of 14m wide and 8m tall.
There are several axis in the world: one axis per object, situated at its center and initially with the same orientation as the global axis; and one unique global axis, at one end of the world.
The global axis is used to place objects in the world.
My idea so far is to calculate the intersection of the fly's predicted path with the wall, and then, with the point of collision, calculate the distance and maneuver to avoid that collision. The problem is that I have not been able to calculate that point with the information neither the direction of the rotation (clockwise or counterclockwise).
- The wall is an infinite plane.
- Fly's rotation only occur around z-axis.
- I am a bit geometry newbie.