Converting Global Coordinates to Character Local Coordinates and Back
I am trying to implement obstacle avoidance behavior from the paper steering behaviours for autonomous agents. What I am stuck at is how do i convert global coordinates (2d) to local coordinates for my character?
Basically Say I am at 1,0 and the enemy is 10,0. I would like to move the origin to 1,0 so I get 9,0 as the enemy coordinates.
开发者_如何学编程What I ended up doing,
to translate to local,
[1 0 -tx] [x]
[0 1 -ty] x [y]
[0 0 1] [1]
then back to global using,
[1 0 tx] [x]
[0 1 ty] x [y]
[0 0 1] [1]
tx,ty is the local char coords and x,y is the enemy char coords.
Just subtract the points.
Relative = Position - moved axis point.
(10,0) - (1,0) = (9,0)
Displacement
Edit:
Using an Affine transformation to convert the entire x,y plane:
Just for numeric issues, lets choose another perspective point: (3,7)
[x] = [ 1 0 -3 ] = [x`] = x -3
[y] [ 0 1 -7 ] = [y`] = y -7
[1] [ 0 0 1 ] = [1 ] = we don't care
Transformation matrix
精彩评论