Skip to content

Fix rotate #285

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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open

Fix rotate #285

wants to merge 3 commits into from

Conversation

drobnyjt
Copy link
Collaborator

Thank you for your contribution to rustBCA!

Before submitting this PR, please make sure you have:

  • Opened an issue
  • Referenced the relevant issue number(s) below
  • Provided a description of the changes below
  • Ensured all tests pass and added any necessary tests for new code

Fixes #284

Description

This PR does two things:

  1. replaces computed linear algebra with a pre-computed rotation matrix for given n
  2. removes panic from rotate_given_surface_normal

Tests

Tested with the following script:

from libRustBCA import *
import numpy as np
delta = 1e-12
num_test = 1000000
mag = np.sqrt((1 - delta)**2 + delta**2)

nx = np.array([(1 - delta)/mag]*num_test)
ny = np.array([delta/mag]*num_test)
nz = np.array([0.0]*num_test)

ux = np.array([-delta]*num_test)
uy = np.random.uniform(-1, 1, num_test)
uz = np.random.uniform(-1, 1, num_test)
umag = np.sqrt(ux*ux + uy*uy + uz*uz)
ux /= umag
uy /= umag
uz /= umag

actually_incident = nx*ux + ny*uy + nz*uz < 0

ux2, uy2, uz2 = rotate_given_surface_normal_vec_py(nx[actually_incident], ny[actually_incident], nz[actually_incident], ux[actually_incident], uy[actually_incident], uz[actually_incident])
ux1, uy1, uz1 = rotate_back_vec_py(nx[actually_incident], ny[actually_incident], nz[actually_incident], ux2, uy2, uz2)

print(np.sum(ux1), np.sum(ux))
print(np.sum(uy1), np.sum(uy))
print(np.sum(uz1), np.sum(uz))

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

Successfully merging this pull request may close these issues.

1 participant