Skip to content
Draft
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
3 changes: 2 additions & 1 deletion examples/fea.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Descartes
using Meshing

# params
beam_size = [50,10,10]
Expand All @@ -17,4 +18,4 @@ for i = 1:hole_ct
global c = diff(c, h)
end

save("fea.ply",HomogenousMesh(c))
save("fea.ply",HomogenousMesh(c, samples=(50,50,50), algorithm=DualContours()))
22 changes: 14 additions & 8 deletions src/frep.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# http://en.wikipedia.org/wiki/Function_representation

# rvechev functions for smooth max and min
rmax(x,y) = (x+y+sqrt((x-y)^2))/2
Copy link
Member Author

Choose a reason for hiding this comment

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

should be x+y under sqrt. also not sure about the division by 2

rmax(x, y, z...) = rmax(x, rmax(y,z...))
rmin(x,y) = (x+y-sqrt((x-y)^2))/2
rmin(x, y, z...) = rmin(x, rmin(y,z...))

function _radius(a,b,r)
if abs(a-b) >= r
return min(a,b)
return rmin(a,b)
else
return b+r*sin(pi/4+asin((a-b)/(r*sqrt(2))))-r
end
Expand All @@ -21,7 +27,7 @@ function FRep(p::Cylinder, v)
x = v[1]*it[1,1]+v[2]*it[1,2]+v[3]*it[1,3]+it[1,4]
y = v[1]*it[2,1]+v[2]*it[2,2]+v[3]*it[2,3]+it[2,4]
z = v[1]*it[3,1]+v[2]*it[3,2]+v[3]*it[3,3]+it[3,4]
max(-z+p.bottom, z-p.height-p.bottom, sqrt(x*x + y*y) - p.radius)
rmax(-z+p.bottom, z-p.height-p.bottom, sqrt(x*x + y*y) - p.radius)
end

function FRep(p::Cuboid, v)
Expand All @@ -31,26 +37,26 @@ function FRep(p::Cuboid, v)
z = v[1]*it[3,1]+v[2]*it[3,2]+v[3]*it[3,3]+it[3,4]
dx, dy, dz = p.dimensions
lbx, lby,lbz = p.lowercorner
max(-x+lbx, x-dx-lbx,
rmax(-x+lbx, x-dx-lbx,
-y+lby, y-dy-lby,
-z+lbz, z-dz-lbz)
end

function FRep(u::CSGUnion, v)
min(FRep(u.left, v),FRep(u.right, v))
rmin(FRep(u.left, v),FRep(u.right, v))
end

function FRep(u::CSGDiff, v)
max(FRep(u.left, v), -FRep(u.right, v))
rmax(FRep(u.left, v), -FRep(u.right, v))
end

function FRep(u::CSGIntersect, v)
max(FRep(u.left, v), FRep(u.right, v))
rmax(FRep(u.left, v), FRep(u.right, v))
end

function FRep(s::Shell, v)
r = FRep(s.primitive, v)
max(r, -r-s.distance)
rmax(r, -r-s.distance)
end

function FRep(u::RadiusedCSGUnion, v)
Expand Down Expand Up @@ -85,5 +91,5 @@ end

function FRep(p::LinearExtrude, v)
r = FRep(s.primitive, v)
max(max(-z,z-p.height), r)
rmax(rmax(-z,z-p.height), r)
end