Skip to content

Commit

Permalink
Update shape.jl
Browse files Browse the repository at this point in the history
- Remove `force`, `torque`, `flux`, `face_forces` from `ShapeModel`
  • Loading branch information
hyrodium committed Oct 14, 2023
1 parent a41fafd commit 5ac2522
Showing 1 changed file with 10 additions and 32 deletions.
42 changes: 10 additions & 32 deletions src/shape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,21 @@ end
A polyhedral shape model of an asteroid.
# Fields
- `nodes` : 1-D array of node positions
- `faces` : 1-D array of vertex indices of faces
- `force` : Thermal recoil force at body-fixed frame (Yarkovsky effect)
- `torque` : Thermal recoil torque at body-fixed frame (YORP effect)
- `face_centers` : Center position of each face
- `face_normals` : Normal vector of each face
- `face_areas` : Area of of each face
- `flux` : Flux on each face. Matrix of size (Number of faces, 3). Three components are:
- `flux[:, 1]` : F_sun, flux of direct sunlight
- `flux[:, 2]` : F_scat, flux of scattered light
- `flux[:, 3]` : F_rad, flux of thermal emission from surrounding surface
- `face_forces` : Thermal force on each face
- `nodes` : Vector of node positions
- `faces` : Vector of vertex indices of faces
- `face_centers` : Center position of each face
- `face_normals` : Normal vector of each face
- `face_areas` : Area of of each face
- `visiblefacets` : Vector of vector of `VisibleFacet`
"""
mutable struct ShapeModel
nodes ::Vector{SVector{3, Float64}}
faces ::Vector{SVector{3, Int}}

force ::MVector{3, Float64}
torque ::MVector{3, Float64}

face_centers ::Vector{SVector{3, Float64}}
face_normals ::Vector{SVector{3, Float64}}
face_areas ::Vector{Float64}

flux ::Matrix{Float64}
face_forces ::Vector{SVector{3, Float64}}
visiblefacets::Vector{Vector{VisibleFacet}}
end

Expand All @@ -72,18 +58,14 @@ end
function load_shape_obj(shapepath; scale=1.0, find_visible_facets=false)
# TODO: use MeshIO.jl
nodes, faces = loadobj(shapepath; scale=scale, static=true, message=false)
force = zero(MVector{3, Float64})
torque = zero(MVector{3, Float64})

face_centers = [face_center(nodes[face]) for face in faces]
face_normals = [face_normal(nodes[face]) for face in faces]
face_areas = [face_area(nodes[face]) for face in faces]

flux = zeros(length(faces), 3)
face_forces = [zero(SVector{3, Float64}) for _ in faces]
visiblefacets = [VisibleFacet[] for _ in faces]

shape = ShapeModel(nodes, faces, force, torque, face_centers, face_normals, face_areas, flux, face_forces, visiblefacets)
shape = ShapeModel(nodes, faces, face_centers, face_normals, face_areas, visiblefacets)
find_visible_facets && find_visiblefacets!(shape)

return shape
Expand Down Expand Up @@ -137,8 +119,7 @@ function grid_to_faces(xs::AbstractVector, ys::AbstractVector, zs::AbstractMatri
ABC = @SVector [i + (j-1)*length(xs), i+1 + (j-1)*length(xs), i + j*length(xs)] # Indices of nodes of △ABC
DCB = @SVector [i+1 + j*length(xs), i + j*length(xs), i+1 + (j-1)*length(xs)] # Indices of nodes of △DCB

push!(faces, ABC)
push!(faces, DCB)
push!(faces, ABC, DCB)
end
end

Expand All @@ -158,18 +139,15 @@ Convert a regular grid (x, y) to a shape model
"""
function load_shape_grid(xs::AbstractVector, ys::AbstractVector, zs::AbstractMatrix; scale=1.0, find_visible_facets=false)
nodes, faces = grid_to_faces(xs, ys, zs)
force = zero(MVector{3, Float64})
torque = zero(MVector{3, Float64})

nodes .*= scale

face_centers = [face_center(nodes[face]) for face in faces]
face_normals = [face_normal(nodes[face]) for face in faces]
face_areas = [face_area(nodes[face]) for face in faces]

flux = zeros(length(faces), 3)
face_forces = [zero(SVector{3, Float64}) for _ in faces]
visiblefacets = [VisibleFacet[] for _ in faces]

shape = ShapeModel(nodes, faces, force, torque, face_centers, face_normals, face_areas, flux, face_forces, visiblefacets)
shape = ShapeModel(nodes, faces, face_centers, face_normals, face_areas, visiblefacets)
find_visible_facets && find_visiblefacets!(shape)

return shape
Expand Down

0 comments on commit 5ac2522

Please sign in to comment.