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

An use mpr float type #47

Merged
merged 7 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Basics/_module.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Andrea Neumayr and Martin Otter, [DLR - Institute of System Dynamics and Control
"""
module Basics

import Modia3D

export trailingPartOfName

export neps, sign_eps, radToDeg
Expand Down
59 changes: 31 additions & 28 deletions src/Basics/constantsAndFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,37 @@


# Epsilon and sign
const neps = sqrt( eps() )
sign_eps(value::Float64; seps::Float64 = 100*neps)::Float64 = value > seps ? 1.0 : (value < -seps ? -1.0 : 0.0)

function normalizeVector(n::SVector{3,Float64})::SVector{3,Float64}
nabs = norm(n)
if nabs <= neps
println("neps ", neps)
println("nabs ", nabs)
@assert(nabs > neps) # && norm(vec) > eps()
# return nothing
else
const neps = sqrt( eps(Modia3D.MPRFloatType) )

function sign_eps(value::T; ) where {T}
seps::T = 100.0*neps
return value > seps ? T(1.0) : (value < -seps ? T(-1.0) : T(0.0))
end

function normalizeVector(n::SVector{3,T}) where {T}
nabs = norm(n)
if nabs <= neps
println("neps ", neps)
println("nabs ", nabs)
@assert(nabs > neps) # && norm(vec) > eps()
# return nothing
end
return n/nabs
end
end

# Standard constants
const radToDeg = 180.0/pi
const radToDeg = 180.0/pi

""" mutable struct BoundingBox - Smallest box that contains a visual element"""
mutable struct BoundingBox
x_min::Float64
x_max::Float64
y_min::Float64
y_max::Float64
z_min::Float64
z_max::Float64
BoundingBox() = new(0.0,0.0,0.0,0.0,0.0,0.0)
BoundingBox(x_min,x_max,y_min,y_max,z_min,z_max) = new(x_min,x_max,y_min,y_max,z_min,z_max)
x_min::Float64
x_max::Float64
y_min::Float64
y_max::Float64
z_min::Float64
z_max::Float64
BoundingBox() = new(0.0,0.0,0.0,0.0,0.0,0.0)
BoundingBox(x_min,x_max,y_min,y_max,z_min,z_max) = new(x_min,x_max,y_min,y_max,z_min,z_max)
end


Expand All @@ -44,17 +47,17 @@ linearMovement(delta_x, tStart, tEnd, time) = delta_x*(time-tStart)/(tEnd-tStart

# Trailing part of type name
function trailingPartOfTypeAsString(obj)::String
name = string( typeof(obj) )
name = string( typeof(obj) )

# Determine trailing solid (after last ".")
i = first(something(findlast(".", name), 0:-1))
return i > 0 && i < length(name) ? name[i+1:end] : name
# Determine trailing solid (after last ".")
i = first(something(findlast(".", name), 0:-1))
return i > 0 && i < length(name) ? name[i+1:end] : name
end

function trailingPartOfName(name::AbstractString)::String
# Determine trailing part of name (after last ".")
i = first(something(findlast(".", name), 0:-1))
return i > 0 && i < length(name) ? name[i+1:end] : name
# Determine trailing part of name (after last ".")
i = first(something(findlast(".", name), 0:-1))
return i > 0 && i < length(name) ? name[i+1:end] : name
end


Expand Down
22 changes: 12 additions & 10 deletions src/Composition/supportPoints.jl
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
function supportPoint(obj::Composition.Object3D, e::SVector{3,Float64})
function supportPoint(obj::Composition.Object3D, e::SVector{3,T}) where {T}
shapeKind = obj.shapeKind
solid::Modia3D.Solid = obj.feature
collisionSmoothingRadius = solid.collisionSmoothingRadius
collisionSmoothingRadius = T(solid.collisionSmoothingRadius)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could introduce variables obj_r_abs/R_abs here for easier reading.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

obj_r_abs = SVector{3, T}(obj.r_abs)
obj_R_abs = SMatrix{3,3,T,9}(obj.R_abs)

if shapeKind == Modia3D.SphereKind
#sphere::Modia3D.Sphere = obj.shape
return Modia3D.supportPoint_Sphere(obj.shape, obj.r_abs, obj.R_abs, e)
return Modia3D.supportPoint_Sphere(obj.shape, obj_r_abs, obj_R_abs, e)
elseif shapeKind == Modia3D.EllipsoidKind
#ellipsoid::Modia3D.Ellipsoid = obj.shape
return Modia3D.supportPoint_Ellipsoid(obj.shape, obj.r_abs, obj.R_abs, e)
return Modia3D.supportPoint_Ellipsoid(obj.shape, obj_r_abs, obj_R_abs, e)
elseif shapeKind == Modia3D.BoxKind
#box::Modia3D.Box = obj.shape
return Modia3D.supportPoint_Box(obj.shape, obj.r_abs, obj.R_abs, e, collisionSmoothingRadius)
return Modia3D.supportPoint_Box(obj.shape, obj_r_abs, obj_R_abs, e, collisionSmoothingRadius)
elseif shapeKind == Modia3D.CylinderKind
#cylinder::Modia3D.Cylinder = obj.shape
return Modia3D.supportPoint_Cylinder(obj.shape, obj.r_abs, obj.R_abs, e, collisionSmoothingRadius)
return Modia3D.supportPoint_Cylinder(obj.shape, obj_r_abs, obj_R_abs, e, collisionSmoothingRadius)
elseif shapeKind == Modia3D.ConeKind
#cone::Modia3D.Cone = obj.shape
return Modia3D.supportPoint_Cone(obj.shape, obj.r_abs, obj.R_abs, e, collisionSmoothingRadius)
return Modia3D.supportPoint_Cone(obj.shape, obj_r_abs, obj_R_abs, e, collisionSmoothingRadius)
elseif shapeKind == Modia3D.CapsuleKind
#capsule::Modia3D.Capsule = obj.shape
return Modia3D.supportPoint_Capsule(obj.shape, obj.r_abs, obj.R_abs, e)
return Modia3D.supportPoint_Capsule(obj.shape, obj_r_abs, obj_R_abs, e)
elseif shapeKind == Modia3D.BeamKind
#beam::Modia3D.Beam = obj.shape
return Modia3D.supportPoint_Beam(obj.shape, obj.r_abs, obj.R_abs, e, collisionSmoothingRadius)
return Modia3D.supportPoint_Beam(obj.shape, obj_r_abs, obj_R_abs, e, collisionSmoothingRadius)
elseif shapeKind == Modia3D.FileMeshKind
#fileMesh::Modia3D.FileMesh = obj.shape
return Modia3D.supportPoint_FileMesh(obj.shape, obj.r_abs, obj.R_abs, e)
return Modia3D.supportPoint_FileMesh(obj.shape, obj_r_abs, obj_R_abs, e)
else
error("not supported shape for support points")
end
Expand Down
3 changes: 2 additions & 1 deletion src/Modia3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ convertAndStripUnit(TargetType, requiredUnit, value) =
numberType(value) <: Unitful.AbstractQuantity && unit.(value) != Unitful.NoUnits ?
convert(TargetType, ustrip.( uconvert.(requiredUnit, value))) : convert(TargetType, value)


# MPRFloatType is used to change betweeen Double64 and Float64 for mpr calculations
const MPRFloatType = Float64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!


# Include sub-modules
include(joinpath("Frames" , "_module.jl"))
Expand Down
Loading