-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sweeplofting and kabsch rotation
- Loading branch information
1 parent
41fc2e9
commit 7511208
Showing
8 changed files
with
445 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Comodo | ||
using GLMakie | ||
using GeometryBasics | ||
using FileIO | ||
using Rotations | ||
|
||
#= | ||
In this demo a mesh is loaded, in this case a triangulated surface from an STL | ||
file. Next the coordinates are rotated, and the unrotated and rotated meshes | ||
are visualized. | ||
=# | ||
|
||
# Loading a mesh | ||
fileName_mesh = joinpath(comododir(),"assets","stl","stanford_bunny_low.stl") | ||
M = load(fileName_mesh) | ||
|
||
# Obtain mesh faces and vertices | ||
F = faces(M) | ||
V1 = togeometrybasics_points(coordinates(M)) | ||
F,V1 = mergevertices(F,V1) | ||
|
||
# Define a rotation tensor using Euler angles | ||
Q = RotXYZ(0.0,0.25*π,0.25*π) | ||
V2 = [GeometryBasics.Point{3, Float64}(Q*v) for v ∈ V1] | ||
|
||
R = kabsch_rot(V2,V1) | ||
V3 = [GeometryBasics.Point{3, Float64}(R*v) for v ∈ V2] | ||
|
||
# Rotate the coordinates | ||
fig = Figure(size = (800,800)) | ||
ax = Axis3(fig[1, 1], aspect = :data) | ||
|
||
hp1 = poly!(ax, GeometryBasics.Mesh(V1,F), color=:green,transparency=false,shading = FastShading) | ||
hp2 = poly!(ax, GeometryBasics.Mesh(V2,F), strokewidth=2,color=:red,shading = FastShading) | ||
hp3 = wireframe!(ax, GeometryBasics.Mesh(V3,F), color=:red,linewidth=2) | ||
|
||
Legend(fig[1, 2],[hp1,hp2,hp3],["Initial","Rotated","Back rotated"]) | ||
|
||
fig | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
using Comodo | ||
using GeometryBasics | ||
using GLMakie | ||
using Rotations | ||
using Statistics | ||
using LinearAlgebra | ||
|
||
testCase = 1 | ||
|
||
if testCase == 1 | ||
# Define guide curve | ||
nc = 51 # Number of points on guide curve | ||
P = Vector{GeometryBasics.Point{3, Float64}}(undef,4) | ||
P[1 ] = GeometryBasics.Point{3, Float64}( 0.0, 0.0, 0.0) | ||
P[2 ] = GeometryBasics.Point{3, Float64}( 1.0, 0.0, 0.0) | ||
P[3 ] = GeometryBasics.Point{3, Float64}( 1.0, 1.0, 0.0) | ||
P[4 ] = GeometryBasics.Point{3, Float64}( 1.0, 1.0, 1.0) | ||
Vc = nbezier(P,nc) # Get Bezier fit points | ||
Vc = [vc.*10 for vc in Vc] | ||
Vc,Sc = evenly_sample(Vc, nc) | ||
|
||
# Define section curves | ||
np = 25 # Number of section points | ||
f(t) = 2.0 + 0.5.*sin(3*t) | ||
V1 = circlepoints(f,np; dir=:acw) | ||
V1,_ = evenly_sample(V1, np) | ||
Q = RotXYZ(0.0,0.5*π,0.0) # Define a rotation tensor using Euler angles | ||
V1 = [Q*v for v ∈ V1] # Rotate the coordinates | ||
|
||
f(t) = 2.0 + 0.5*sin(3*t) | ||
V2 = circlepoints(f,np; dir=:acw) | ||
V2,_ = evenly_sample(V2, np) | ||
V2 = [v2 .+ Vc[end] for v2 ∈ V2] | ||
elseif testCase == 2 | ||
# Define guide curve | ||
nc = 75 # Number of points on guide curve | ||
P = Vector{GeometryBasics.Point{3, Float64}}(undef,4) | ||
P[1 ] = GeometryBasics.Point{3, Float64}( 0.0, 0.0, 0.0) | ||
P[2 ] = GeometryBasics.Point{3, Float64}( 1.0, 0.0, 0.0) | ||
P[3 ] = GeometryBasics.Point{3, Float64}( 2.0, 0.0, 0.0) | ||
P[4 ] = GeometryBasics.Point{3, Float64}( 3.0, 0.0, 0.0) | ||
Vc = nbezier(P,nc) # Get Bezier fit points | ||
Vc = [vc.*10 for vc in Vc] | ||
Vc,Sc = evenly_sample(Vc, nc) | ||
|
||
# Define section curves | ||
np = 35 # Number of section points | ||
f(t) = 2.0 + 0.5.*sin(3*t) | ||
V1 = circlepoints(f,np; dir=:acw) | ||
V1,_ = evenly_sample(V1, np) | ||
Q = RotXYZ(0.0,0.5*π,0.0) # Define a rotation tensor using Euler angles | ||
V1 = [(Q*v) .+ Vc[1] for v ∈ V1] # Rotate the coordinates | ||
|
||
f(t) = 2.0 + 0.5*sin(3*t) | ||
V2 = circlepoints(f,np; dir=:acw) | ||
V2,_ = evenly_sample(V2, np) | ||
Q = RotXYZ(0.0,0.5*π,0.0) # Define a rotation tensor using Euler angles | ||
V2 = [(Q*v) .+ Vc[end] for v ∈ V2] | ||
elseif testCase == 3 | ||
nc = 201 # Number of points on guide curve | ||
r = 10.0 | ||
a = 4*π | ||
Vc = [GeometryBasics.Point{3, Float64}(r*cos(t),r*sin(t),10.0*(t/(a/2))) for t ∈ range(0,a,nc)] | ||
|
||
# Define section curves | ||
np = 50 # Number of section points | ||
|
||
# Section 1 | ||
f(t) = 1.5 + 0.5.*sin(3*t) | ||
V1 = circlepoints(f,np; dir=:cw) | ||
V1,_ = evenly_sample(V1, np) | ||
Q = RotXYZ(0.5*π,0.0,0.0) # Define a rotation tensor using Euler angles | ||
V1 = [Q*v for v ∈ V1] # Rotate the coordinates | ||
|
||
# Ensure section is orthogonal to guide curve | ||
n3_1 = Q*Vec3{Float64}(0.0,0.0,-1.0) | ||
n2_1 = Q*Vec3{Float64}(1.0,0.0,0.0) | ||
n1_1 = normalizevector(cross(n3_1,n2_1)) | ||
S11 = mapreduce(permutedims,vcat,[n1_1,n2_1,n3_1]) | ||
|
||
n3_1 = normalizevector(normalizevector(Vc[2]-Vc[1])) | ||
n2_1 = normalizevector(cross(normalizevector(V1[1]),n3_1)) | ||
n1_1 = normalizevector(cross(n3_1,n2_1)) | ||
S12 = mapreduce(permutedims,vcat,[n1_1,n2_1,n3_1]) | ||
|
||
R = RotMatrix3{Float64}(S12\S11) | ||
V1 = [R*v for v ∈ V1] | ||
V1= [v .+ Vc[1] for v ∈ V1] | ||
|
||
# Section 2 | ||
f(t) = 4 + 1.5*sin(5*t) | ||
V2 = circlepoints(f,np; dir=:cw) | ||
V2,_ = evenly_sample(V2, np) | ||
Q1 = RotXYZ(0.5*π,0.0,0.0) # Define a rotation tensor using Euler angles | ||
Q2 = RotXYZ(0.0,-0.25*π,0.0) # Define a rotation tensor using Euler angles | ||
Q = Q2*Q1 | ||
V2 = [Q*v for v ∈ V2] # Rotate the coordinates | ||
|
||
# Ensure section is orthogonal to guide curve | ||
n3_2 = Q*Vec3{Float64}(0.0,0.0,-1.0) | ||
n2_2 = Q*Vec3{Float64}(1.0,0.0,0.0) | ||
n1_2 = normalizevector(cross(n3_2,n2_2)) | ||
S21 = RotMatrix3{Float64}(mapreduce(permutedims,vcat,[n1_2,n2_2,n3_2])) | ||
|
||
n3_2 = normalizevector(normalizevector(Vc[2]-Vc[1])) | ||
n2_2 = normalizevector(cross(normalizevector(V1[1]),n3_1)) | ||
n1_2 = normalizevector(cross(n3_1,n2_1)) | ||
S22 = mapreduce(permutedims,vcat,[n1_1,n2_1,n3_1]) | ||
|
||
R = RotMatrix3{Float64}(S22\S21) | ||
V2 = [R*v for v ∈ V2] # Rotate the coordinates | ||
V2 = [v .+ Vc[end] for v ∈ V2] | ||
end | ||
|
||
|
||
|
||
######### | ||
|
||
# face_type=:quad | ||
F,V = sweeploft(Vc,V1,V2; face_type=:quad, num_twist=0) | ||
F = invert_faces(F) | ||
|
||
|
||
# Visualization | ||
fig = Figure(size = (800,800)) | ||
ax = Axis3(fig[1, 1],aspect = :data,title="Swept lofting") | ||
|
||
stepRange1 = -4:1:4 | ||
hSlider1 = Slider(fig[2, 1], range = stepRange1, startvalue = 0,linewidth=30) | ||
|
||
# scatter!(ax, Vc,markersize=8,color=:black) | ||
hp1 = lines!(ax, Vc,linewidth=4,color=:black) | ||
|
||
scatter!(ax, V1,markersize=8,color=:blue) | ||
hp2 = lines!(ax, V1,linewidth=4,color=:blue) | ||
|
||
scatter!(ax, V2,markersize=8,color=:red) | ||
hp3 = lines!(ax, V2,linewidth=4,color=:red) | ||
|
||
hp1 = poly!(ax, GeometryBasics.Mesh(V,F), strokecolor=:black, strokewidth=1,color=:white,transparency=false,shading = FastShading) | ||
# hp1 = mesh!(ax, GeometryBasics.Mesh(V,F), color=:white,transparency=false,shading = FastShading) | ||
|
||
on(hSlider1.value) do stepIndex1 | ||
F,V = sweeploft(Vc,V1,V2; face_type=:quad, num_twist=stepIndex1) | ||
F = invert_faces(F) | ||
hp1[1] = GeometryBasics.Mesh(V,F) | ||
end | ||
|
||
fig | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.