Skip to content

Fix to plane wave with negative azimuth angle #2592

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

Merged
merged 1 commit into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Fixed
- Arrow lengths are now scaled consistently in the X and Y directions,
and their lengths no longer exceed the height of the plot window.
- Arrow lengths are now scaled consistently in the X and Y directions, and their lengths no longer exceed the height of the plot window.
- Bug in `PlaneWave` defined with a negative `angle_theta` which would lead to wrong injection.

## [2.9.0rc1] - 2025-06-10

Expand Down
2 changes: 1 addition & 1 deletion tidy3d/components/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def _angle_theta_actual(self, background_n: Numpy) -> Numpy:
k0 = 2 * np.pi * np.array(self.freqs) / C_0 * background_n
kx, ky = self.in_plane_k(background_n)
k_perp = np.sqrt(kx**2 + ky**2)
return np.real(np.arcsin(k_perp / k0))
return np.real(np.arcsin(k_perp / k0)) * np.sign(self.angle_theta)
Comment on lines 318 to +321
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Document why we need to preserve angle_theta's sign in this calculation

Suggested change
k0 = 2 * np.pi * np.array(self.freqs) / C_0 * background_n
kx, ky = self.in_plane_k(background_n)
k_perp = np.sqrt(kx**2 + ky**2)
return np.real(np.arcsin(k_perp / k0))
return np.real(np.arcsin(k_perp / k0)) * np.sign(self.angle_theta)
k0 = 2 * np.pi * np.array(self.freqs) / C_0 * background_n
kx, ky = self.in_plane_k(background_n)
k_perp = np.sqrt(kx**2 + ky**2)
# Preserve the sign of angle_theta to handle both positive and negative angles correctly
return np.real(np.arcsin(k_perp / k0)) * np.sign(self.angle_theta)


def _rotate_points_z(self, points: Numpy, background_n: Numpy) -> Numpy:
"""Rotate points to new coordinates where z is the propagation axis."""
Expand Down
Loading