Skip to content

Commit

Permalink
local aniso from triangles
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcaixeta committed Oct 23, 2024
1 parent 7de01d0 commit 6fa800c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/parametrization/geometric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ function localanisotropies(
LocalAnisotropy(quat, m)
end

function localanisotropies(
::Type{Geometric},
trs::GeometrySet,
magnitude::AbstractVector,
)
q = mapreduce(vcat, trs) do tr
v = vertices(tr)
c = centroid(tr)
n = [ustrip(i) for i in normal(tr)]
p = minpt(tr)
v1 = [ustrip(i) for i in (p - c)]
v1 ./= sum(v1)
v2 = cross(v1, n)

m = SMatrix{3,3}(v1..., v2..., n...)
det(m) < 0 && (m = Diagonal(SVector{3}([-1, 1, 1])) * m)

dcm_to_quat(DCM(m))
end
mag = repeat(magnitude, 1, length(q))
LocalAnisotropy(q, mag)
end

function pca(X, simplify)
N = size(X, 1)
M = MultivariateStats.fit(PCA, ustrip.(X), maxoutdim = N, pratio = 1)
Expand Down Expand Up @@ -93,3 +116,12 @@ function pca(X, simplify)

λ[1:N], SMatrix{3,3}(v')
end


function minpt(tr)
minz = to(boundingbox(tr).min)[3]
vc = vertices(tr)
m = [to(p)[3] == minz for p in vc]
out = vc[m]
out isa Point ? out : out[1]
end

0 comments on commit 6fa800c

Please sign in to comment.