Skip to content

Commit 8d78a7f

Browse files
Merge pull request #51 from ModiaSim/an_mprWithDouble64
An mpr with double64
2 parents f4c0dbb + bf438ac commit 8d78a7f

File tree

10 files changed

+57
-56
lines changed

10 files changed

+57
-56
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ version = "0.5.1-dev"
66
[deps]
77
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
88
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
9+
DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78"
910
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1011
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
1112
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -21,6 +22,7 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
2122
[compat]
2223
Colors = "0.12, 0.11, 0.10"
2324
DataFrames = "0.22, 0.21, 0.20, 0.19"
25+
DoubleFloats = "1.1"
2426
JSON = "0.21"
2527
ModiaLang = "0.8.1"
2628
OrderedCollections = "1.4, 1.3, 1.2, 1.1"

src/Basics/_module.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Modia3D
1717

1818
export trailingPartOfName
1919

20-
export neps, sign_eps, radToDeg
20+
export nepsType, neps, sign_eps, radToDeg
2121
export getAndCheckFullLibraryPath, getEnvironmentVariable
2222

2323
export normalizeVector, BoundingBox

src/Basics/constantsAndFunctions.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@
77

88

99
# Epsilon and sign
10-
const neps = sqrt( eps(Modia3D.MPRFloatType) )
10+
const neps = sqrt( eps() )
1111

12-
function sign_eps(value::T; ) where {T}
13-
seps::T = 100.0*neps
12+
nepsType(::Type{T}) where {T} = sqrt( eps(T) ) # mpr and bounding box calculation use this
13+
14+
function sign_eps(value::T) where {T}
15+
seps::T = 100.0*nepsType(T)
1416
return value > seps ? T(1.0) : (value < -seps ? T(-1.0) : T(0.0))
1517
end
1618

1719
function normalizeVector(n::SVector{3,T}) where {T}
1820
nabs = norm(n)
19-
if nabs <= neps
20-
println("neps ", neps)
21+
if nabs <= nepsType(T)
22+
println("neps ", nepsType(T))
2123
println("nabs ", nabs)
22-
@assert(nabs > neps) # && norm(vec) > eps()
24+
@assert(nabs > nepsType(T)) # && norm(vec) > eps()
2325
# return nothing
2426
end
2527
return n/nabs

src/Frames/interpolation.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# This file is part of module
55
# Modia3D.Frames (Modia3D/Frames/_module.jl)
66
#
7-
const seps = sqrt(eps())
87

98

109
"""
@@ -76,7 +75,7 @@ struct Path
7675

7776
function Path(r::AbstractVector, q::AbstractVector=Quaternion[];
7877
v::AbstractVector=ones(length(r)),
79-
seps=sqrt(eps()) )
78+
seps=Modia3D.neps )
8079
nframes = size(r, 1)
8180
@assert(seps > 0.0)
8281
@assert(nframes > 1)

src/Modia3D.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ convertAndStripUnit(TargetType, requiredUnit, value) =
9696
convert(TargetType, ustrip.( uconvert.(requiredUnit, value))) : convert(TargetType, value)
9797

9898
# MPRFloatType is used to change betweeen Double64 and Float64 for mpr calculations
99+
using DoubleFloats
99100
const MPRFloatType = Float64
100101

101102
# Include sub-modules

src/Shapes/boundingBoxes.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,21 @@ end
7878
halfDiameter = T(0.5*shape.diameter)
7979
if shape.axis == 1
8080
enorm = norm(SVector(e_abs[2], e_abs[3]))
81-
if enorm <= Modia3D.neps
81+
if enorm <= Modia3D.nepsType(T)
8282
return Basics.sign_eps(e_abs[1])*SVector(halfLength, 0.0, 0.0)
8383
else
8484
return Basics.sign_eps(e_abs[1])*SVector(halfLength, 0.0, 0.0) + SVector(0.0, (halfDiameter)*e_abs[2], (halfDiameter)*e_abs[3])/enorm
8585
end
8686
elseif shape.axis == 2
8787
enorm = norm(SVector(e_abs[3], e_abs[1]))
88-
if enorm <= Modia3D.neps
88+
if enorm <= Modia3D.nepsType(T)
8989
return Basics.sign_eps(e_abs[2])*SVector(0.0, halfLength, 0.0)
9090
else
9191
return Basics.sign_eps(e_abs[2])*SVector(0.0, halfLength, 0.0) + SVector((halfDiameter)*e_abs[1], 0.0, (halfDiameter)*e_abs[3])/enorm
9292
end
9393
else
9494
enorm = norm(SVector(e_abs[1], e_abs[2]))
95-
if enorm <= Modia3D.neps
95+
if enorm <= Modia3D.nepsType(T)
9696
return Basics.sign_eps(e_abs[3])*SVector(0.0, 0.0, halfLength)
9797
else
9898
return Basics.sign_eps(e_abs[3])*SVector(0.0, 0.0, halfLength) + SVector((halfDiameter)*e_abs[1], (halfDiameter)*e_abs[2], 0.0)/enorm
@@ -137,15 +137,15 @@ end
137137
return SVector(shapeLength, 0.0, 0.0) # apex is support point
138138
else # frustum of a cone
139139
enorm = norm(SVector(e_abs[2], e_abs[3]))
140-
if enorm > Modia3D.neps
140+
if enorm > Modia3D.nepsType(T)
141141
return SVector(shapeLength, 0.0, 0.0) + SVector(0.0, topRadius*e_abs[2], topRadius*e_abs[3]) / enorm # point on top circle is support point
142142
else
143143
return SVector(shapeLength, 0.0, 0.0) # top circle center is support point
144144
end
145145
end
146146
else
147147
enorm = norm(SVector(e_abs[2], e_abs[3]))
148-
if enorm > Modia3D.neps
148+
if enorm > Modia3D.nepsType(T)
149149
return SVector(0.0, baseRadius*e_abs[2], baseRadius*e_abs[3]) / enorm # point on base circle is support point
150150
else
151151
return SVector{3,T}(0.0, 0.0, 0.0) # base circle center is support point
@@ -158,15 +158,15 @@ end
158158
return SVector(0.0, shapeLength, 0.0) # apex is support point
159159
else # frustum of a cone
160160
enorm = norm(SVector(e_abs[3], e_abs[1]))
161-
if enorm > Modia3D.neps
161+
if enorm > Modia3D.nepsType(T)
162162
return SVector(0.0, shapeLength, 0.0) + SVector(topRadius*e_abs[1], 0.0, topRadius*e_abs[3]) / enorm # point on top circle is support point
163163
else
164164
return SVector(0.0, shapeLength, 0.0) # top circle center is support point
165165
end
166166
end
167167
else
168168
enorm = norm(SVector(e_abs[3], e_abs[1]))
169-
if enorm > Modia3D.neps
169+
if enorm > Modia3D.nepsType(T)
170170
return SVector(baseRadius*e_abs[1], 0.0, baseRadius*e_abs[3]) / enorm # point on base circle is support point
171171
else
172172
return SVector{3,T}(0.0, 0.0, 0.0) # base circle center is support point
@@ -179,15 +179,15 @@ end
179179
return SVector(0.0, 0.0, shapeLength) # apex is support point
180180
else # frustum of a cone
181181
enorm = norm(SVector(e_abs[1], e_abs[2]))
182-
if enorm > Modia3D.neps
182+
if enorm > Modia3D.nepsType(T)
183183
return SVector(0.0, 0.0, shapeLength) + SVector(topRadius*e_abs[1], topRadius*e_abs[2], 0.0) / enorm # point on top circle is support point
184184
else
185185
return SVector(0.0, 0.0, shapeLength) # top circle center is support point
186186
end
187187
end
188188
else
189189
enorm = norm(SVector(e_abs[1], e_abs[2]))
190-
if enorm > Modia3D.neps
190+
if enorm > Modia3D.nepsType(T)
191191
return SVector(baseRadius*e_abs[1], baseRadius*e_abs[2], 0.0) / enorm # point on base circle is support point
192192
else
193193
return SVector{3,T}(0.0, 0.0, 0.0) # base circle center is support point
@@ -205,21 +205,21 @@ end
205205
halfThickness = T(0.5*shape.thickness)
206206
if shape.axis == 1
207207
enorm = norm(SVector(e_abs[1], e_abs[2]))
208-
if enorm <= Modia3D.neps
208+
if enorm <= Modia3D.nepsType(T)
209209
return SVector(Basics.sign_eps(e_abs[1])*halfLength, 0.0, Basics.sign_eps(e_abs[3])*halfThickness)
210210
else
211211
return SVector(Basics.sign_eps(e_abs[1])*halfLength, 0.0, Basics.sign_eps(e_abs[3])*halfThickness) + SVector(halfWidth*e_abs[1], halfWidth*e_abs[2], 0.0)/enorm
212212
end
213213
elseif shape.axis == 2
214214
enorm = norm(SVector(e_abs[2], e_abs[3]))
215-
if enorm <= Modia3D.neps
215+
if enorm <= Modia3D.nepsType(T)
216216
return SVector(Basics.sign_eps(e_abs[1])*halfThickness, Basics.sign_eps(e_abs[2])*halfLength, 0.0)
217217
else
218218
return SVector(Basics.sign_eps(e_abs[1])*halfThickness, Basics.sign_eps(e_abs[2])*halfLength, 0.0) + SVector(0.0, halfWidth*e_abs[2], halfWidth*e_abs[3])/enorm
219219
end
220220
else
221221
enorm = norm(SVector(e_abs[3], e_abs[1]))
222-
if enorm <= Modia3D.neps
222+
if enorm <= Modia3D.nepsType(T)
223223
return SVector(0.0, Basics.sign_eps(e_abs[2])*halfThickness, Basics.sign_eps(e_abs[3])*halfLength)
224224
else
225225
return SVector(0.0, Basics.sign_eps(e_abs[2])*halfThickness, Basics.sign_eps(e_abs[3])*halfLength) + SVector(halfWidth*e_abs[1], 0.0, halfWidth*e_abs[3])/enorm

src/Shapes/computePropertiesFileMes.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# All faces should be specified in right-handed/counter-clockwise order!
1515

1616

17-
neps = sqrt(eps())
1817

1918
function helpingFunc(w0,w1,w2)
2019
tmp0 = w0 + w1
@@ -70,7 +69,7 @@ function computeMassProperties(vertices::Vector{SVector{3,Float64}}, triangle_in
7069
end
7170

7271
volume = integral[1]
73-
if volume > neps
72+
if volume > Modia3D.neps
7473
# center of volume
7574
centroid = [integral[2], integral[3], integral[4]]/volume
7675

src/contactDetection/ContactDetectionMPR/ContactDetectionMPR_handler.jl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Base.:isequal(key1::DistanceKey, key2::DistanceKey) =
9494

9595

9696
"""
97-
handler = ContactDetectionMPR_handler(;tol_rel = 1e-4, niter_max=100, neps=sqrt(eps()))
97+
handler = ContactDetectionMPR_handler(;tol_rel = 1e-7, niter_max=100)
9898
9999
Generate a new contact handler for usage of the MPR algorithm
100100
The handler instance contains all information
@@ -105,8 +105,6 @@ about the contact situation.
105105
- `tol_rel`: Relative tolerance to compute the contact point (> 0.0)
106106
- `niter_max`: Maximum number of iterations of the MPR algorithm. If this number is reached,
107107
an error occurs (> 0).
108-
- `neps`: Small number used to check whether a floating number is close to zero (> 0.0).
109-
110108
"""
111109
mutable struct ContactDetectionMPR_handler{T} <: Modia3D.AbstractContactDetection
112110
distanceComputed::Bool
@@ -117,7 +115,6 @@ mutable struct ContactDetectionMPR_handler{T} <: Modia3D.AbstractContactDetectio
117115

118116
tol_rel::T
119117
niter_max::Int
120-
neps::T
121118

122119
contactPairs::Composition.ContactPairs
123120

@@ -127,12 +124,10 @@ mutable struct ContactDetectionMPR_handler{T} <: Modia3D.AbstractContactDetectio
127124
defaultContactSphereDiameter::Float64
128125

129126
function ContactDetectionMPR_handler{T}(;tol_rel = 1.0e-7,
130-
niter_max = 100 ,
131-
neps = sqrt(eps(T))) where {T}
127+
niter_max = 100) where {T}
132128
@assert(tol_rel > 0.0)
133129
@assert(niter_max > 0)
134-
@assert(neps > 0.0)
135-
new(false, Dict{PairID,ContactPair}(), Dict{PairID,ContactPair}(), 42.0, tol_rel, niter_max, neps)
130+
new(false, Dict{PairID,ContactPair}(), Dict{PairID,ContactPair}(), 42.0, tol_rel, niter_max)
136131
end
137132
end
138133
ContactDetectionMPR_handler() = ContactDetectionMPR_handler{Modia3D.MPRFloatType}()

src/contactDetection/ContactDetectionMPR/analyzeMPR.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ mutable struct Plane
2020
end
2121

2222

23-
function intersect3DSegmentPlane(seg::Segment, plane::Plane, neps)
23+
function intersect3DSegmentPlane(seg::Segment, plane::Plane)
2424
u = seg.P1 - seg.P0
2525
w = seg.P0 - plane.V0
2626

2727
dividend = -dot(plane.n, w)
2828
divisor = dot(plane.n, u)
29+
neps = Modia3D.nepsType(T)
2930

3031
# checks if segment and plane are parallel
3132
if abs(divisor) < neps # segment is parallel to plane
@@ -53,11 +54,11 @@ end
5354
pointInTriangle(p,a,b,c) = (sameSideTriangle(p,a,b,c) && sameSideTriangle(p,b,a,c) && sameSideTriangle(p,c,a,b))
5455

5556

56-
function doesRayIntersectPortal(r1,r2,r3,point,neps)
57+
function doesRayIntersectPortal(r1,r2,r3,point)
5758
plane = Plane(r1,r2,r3)
5859
segment = Segment(point, SVector(0.0, 0.0, 0.0))
5960

60-
(value, intersectionPoint) = intersect3DSegmentPlane(segment, plane, neps)
61+
(value, intersectionPoint) = intersect3DSegmentPlane(segment, plane)
6162
if value == 1
6263
if !pointInTriangle(intersectionPoint, r1, r2, r3)
6364
error("Ray = ", point ," does not intersect portal (r1,r2,r3) = ", r1, r2, r3)
@@ -68,10 +69,10 @@ function doesRayIntersectPortal(r1,r2,r3,point,neps)
6869
return true
6970
end
7071

71-
function analyzeFinalPortal(r1, r2, r3, r4, neps)
72+
function analyzeFinalPortal(r1, r2, r3, r4)
7273
plane = Plane(r1,r2,r3)
7374
segment = Segment(r4, SVector(0.0, 0.0, 0.0))
74-
(value, intersectionPoint) = intersect3DSegmentPlane(segment, plane, neps)
75+
(value, intersectionPoint) = intersect3DSegmentPlane(segment, plane)
7576
if value == 1
7677
if !pointInTriangle(intersectionPoint, r1, r2, r3)
7778
println("Ray r4 = ", r4 ," is not intersecting last portal (r1,r2,r3) = ", r1, r2, r3)

0 commit comments

Comments
 (0)