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

Add orthogonal and isparallel function #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lijas
Copy link

@lijas lijas commented Mar 7, 2023

I have wanted this a couple of times :)

@codecov-commenter
Copy link

codecov-commenter commented Mar 7, 2023

Codecov Report

Patch coverage: 73.33% and project coverage change: -0.30 ⚠️

Comparison is base (96f6bfa) 98.22% compared to head (c82f4dc) 97.92%.

📣 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     
Impacted Files Coverage Δ
src/Tensors.jl 94.44% <ø> (ø)
src/math_ops.jl 96.80% <73.33%> (-3.21%) ⬇️

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -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)
Copy link
Member

@KnutAM KnutAM Mar 7, 2023

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)

Suggested change
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)

Copy link
Member

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?

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.

Copy link
Member

@KnutAM KnutAM Mar 7, 2023

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)

@KnutAM
Copy link
Member

KnutAM commented Mar 7, 2023

Cool!
Perhaps also the orthogonal can be generalized to 2nd order tensors?

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.

5 participants