Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with rotation matrix #1

Open
Sirorezka opened this issue Jan 29, 2024 · 0 comments
Open

Issues with rotation matrix #1

Sirorezka opened this issue Jan 29, 2024 · 0 comments

Comments

@Sirorezka
Copy link

Sirorezka commented Jan 29, 2024

Hi, sry for bothering with this small issue, but I've found that your implementation of the rotation could be improved:

Your version:

    if np.random.uniform() < prob:
        angle = np.random.uniform(0, 360)
        rotation_matrix = np.array([[np.cos(angle), -np.sin(angle)], [np.sin(angle), np.cos(angle)]])
        data[:,:2] = data[:,:2].dot(rotation_matrix) 

Better version:

  1. convert angle to radians before applying numpy
  2. Usually you multiply rotation matrix from left side (R * X), thus in your case you should transpose rotation matrix to get same numbers.
    This is what you should have after multiplication:
    x′=xcos(θ)−ysin(θ)
    y′=xsin(θ)+ycos(θ)
    if np.random.uniform() < prob:
        angle = np.random.uniform(0, 360) / 180 * np.pi
        rotation_matrix = np.array([[np.cos(angle), -np.sin(angle)], [np.sin(angle), np.cos(angle)]])
        data[:,:2] = data[:,:2].dot(rotation_matrix.T) 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant