-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add orthogonal and isparallel function #195
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #195 +/- ##
==========================================
- Coverage 98.22% 97.92% -0.30%
==========================================
Files 17 17
Lines 1238 1253 +15
==========================================
+ Hits 1216 1227 +11
- Misses 22 26 +4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@@ -378,3 +378,32 @@ function rotate(x::SymmetricTensor{4}, args...) | |||
R = rotation_tensor(args...) | |||
return unsafe_symmetric(otimesu(R, R) ⊡ x ⊡ otimesu(R', R')) | |||
end | |||
|
|||
isparallel(v1::Vec{3}, v2::Vec{3}) = isapprox(Tensors.cross(v1,v2), zero(v1), atol = 1e-14) |
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.
Can we get rid of the absolute tolerance by doing this (which also generalizes to second order)
isparallel(v1::Vec{3}, v2::Vec{3}) = isapprox(Tensors.cross(v1,v2), zero(v1), atol = 1e-14) | |
isparallel(v1::Vec, v2::Vec) = abs(dot(v1,v2)) ≈ norm(v1)*norm(v2) | |
isparallel(a::SecondOrderTensor, b::SecondOrderTensor) = abs(dcontract(a,b)) ≈ norm(a)*norm(b) |
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.
≈
also uses a tolerance though, right?
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.
This cries for a user-defined tolerance with some default value. Think of it conversely: any tolerance describes a cone around one vector in which all vectors are considered as parallel to the reference vector. Same with orthogonality.
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.
≈
also uses a tolerance though, right?
Yes, but a relative one, right? Which works since we are not comparing zeros. I agree with @dkarrasch though that an optional input should be used instead, perhaps isparallel(a,b; kwargs...) = isapprox(abs(dot(v1,v2)), norm(v1)*norm(v2); kwargs...)
?
(I guess a pure angular tolerance could have numerical issues around zero-length vectors)
Cool! |
I have wanted this a couple of times :)