Skip to content

Instantly share code, notes, and snippets.

@nyukhalov
Created December 23, 2018 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nyukhalov/153d4788eadeb341f69a6f6e11a99436 to your computer and use it in GitHub Desktop.
Save nyukhalov/153d4788eadeb341f69a6f6e11a99436 to your computer and use it in GitHub Desktop.
Homogenous Transformation for Particle Filter
import numpy as np
import math
def h_transform(observation_coords, particle_coords, particle_heading):
mat = np.matrix([
[math.cos(particle_heading), -math.sin(particle_heading), particle_coords[0]],
[math.sin(particle_heading), math.cos(particle_heading), particle_coords[1]],
[0, 0, 1]
])
vec = np.matrix([
[observation_coords[0]],
[observation_coords[1]],
[1]
])
ret = mat * vec
return (ret.item(0), ret.item(1))
observation_coords = (0,-4)
particle_coords = (4,5)
particle_heading = -math.pi / 2
print(h_transform(observation_coords, particle_coords, particle_heading))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment