-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
src/math/quaternion_operations.hpp
Outdated
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]; | ||
} | ||
} |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
src/math/quaternion_operations.hpp
Outdated
-a * e1[1] / sqrt(e1[0] * e1[0] + e1[1] * e1[1]), | ||
a * e1[0] / sqrt(e1[0] * e1[0] + e1[1] * e1[1]), |
There was a problem hiding this comment.
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.,
};
I think that I've addressed the comments, please take another look. |
Add function to compute quaternion from material axis tangent and twist parameter.