Skip to content

Issues with rotation matrix #1

@Sirorezka

Description

@Sirorezka

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) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions