Skip to content

Fix rotate#285

Closed
drobnyjt wants to merge 3 commits into
devfrom
fix_rotate
Closed

Fix rotate#285
drobnyjt wants to merge 3 commits into
devfrom
fix_rotate

Conversation

@drobnyjt

Copy link
Copy Markdown
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))

@drobnyjt drobnyjt closed this Aug 5, 2025
@drobnyjt drobnyjt deleted the fix_rotate branch August 5, 2025 20:14
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