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

Quaternion from tangent and twist #348

Merged
merged 3 commits into from
Feb 7, 2025
Merged

Quaternion from tangent and twist #348

merged 3 commits into from
Feb 7, 2025

Conversation

deslaughter
Copy link
Collaborator

Add function to compute quaternion from material axis tangent and twist parameter.

@deslaughter deslaughter added the enhancement New feature or request label Feb 5, 2025
@deslaughter deslaughter requested a review from ddement February 5, 2025 00:18
@deslaughter deslaughter self-assigned this Feb 5, 2025
@faisal-bhuiyan faisal-bhuiyan self-requested a review February 5, 2025 19:36
Comment on lines 65 to 72
size_t max_idx{0};
double max_num{vals[0]};
for (auto i = 1U; i < vals.size(); ++i) {
if (vals[i] > max_num) {
max_idx = i;
max_num = vals[i];
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe there exists an std algorithm to do this, which we could utilize rather than rolling out our own.

    auto max_element_iter = std::max_element(vals.begin(), vals.end());
    auto max_idx = std::distance(vals.begin(), max_element_iter);
    auto max_num = *max_element_iter;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

Comment on lines 315 to 316
-a * e1[1] / sqrt(e1[0] * e1[0] + e1[1] * e1[1]),
a * e1[0] / sqrt(e1[0] * e1[0] + e1[1] * e1[1]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couple comments

  • This returns NaN when the tangent is the z-axis, i.e. e1 = e2 = 0. -- we should probably check for div by zero here
  • We could simplify this by introducing a local variable as such
    const auto denominator = std::sqrt(e1[0] * e1[0] + e1[1] * e1[1]);
    const Array_3 e2{
        -a * e1[1] / denominator,
        a * e1[0] / denominator,
        0.,
    };

@deslaughter
Copy link
Collaborator Author

I think that I've addressed the comments, please take another look.

@deslaughter deslaughter merged commit cc9d2cf into main Feb 7, 2025
17 checks passed
@deslaughter deslaughter deleted the tangent-twist-quat branch February 7, 2025 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants