Skip to content

Instantly share code, notes, and snippets.

@dpsanders
Created February 15, 2021 18:20
Show Gist options
  • Save dpsanders/ae0db1de5bed6df00beed662e5f65ba0 to your computer and use it in GitHub Desktop.
Save dpsanders/ae0db1de5bed6df00beed662e5f65ba0 to your computer and use it in GitHub Desktop.
using IntervalArithmetic
using IntervalConstraintProgramming
using ModelingToolkit # currently (15 Feb 2021) requires version 3 of ModelingToolkit
using AbstractPlotting
using Colors
using WGLMakie
"Plot a vector of `IntervalBox`es in 3D"
function plot3D_makie!(scene, data, color=nothing)
positions = [Point3f0(mid(X)) for X in data]
scales = [Vec3f0(diam.(X)) for X in data]
xs = Float32[x[1] for x in positions]
ys = Float32[x[2] for x in positions]
zs = Float32[x[3] for x in positions]
local colors
# make a varying palette if no colour is specified:
if color == nothing
minx, maxx = extrema(xs)
miny, maxy = extrema(ys)
minz, maxz = extrema(zs)
colors = RGBA{Float32}[
RGBA( (xs[i] - minx) / (maxx - minx),
(ys[i] - miny) / (maxy - miny),
(zs[i] - minz) / (maxz - minz),
0.5f0 )
for i in 1:length(data)
];
else
colors = [color for X in data]
end
cube = Rect3D(Vec3f0(-0.5, -0.5, -0.5), Vec3f0(1, 1, 1)) # origin, widths
meshscatter!(scene, positions, marker=cube, markersize=scales, color=colors, transparency=true)
end
vars = @variables x, y, z
X = IntervalBox(interval(-2.5, 2.5), 3) # box to search in
C1 = Separator(vars, y - x^2 == 0)
C2 = Separator(vars, z - x^3 == 0)
p1 = pave(C1, X, 0.1)
p2 = pave(C2, X, 0.1)
p3 = pave(C1 ∩ C2, X, 0.2)
scene = Scene(resolution=(500, 500))
plot3D_makie!(scene, p1.boundary, RGBA(0, 0, 1, 0.2f0))
plot3D_makie!(scene, p2.boundary, RGBA(0, 1, 0, 0.2f0))
plot3D_makie!(scene, p3.boundary, RGBA(1, 0, 0, 1.0f0))
scene
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment