 # 3D bin packaging using Convex.jl

Intent :Write a convex function that takes a set of points of shape (m,n) basically convexhull points by reading a CAD model.

1. The function must return a Variable(from Convex.jl) of shape/size of the original vector (to be used in optimization later - i have to estimate the coordinates) plus a set of affine constraints to keep it convex.

Here’s the code for the function

``````function vrep(v)
λ = Variable(size(v))
x = Variable(size(v))
c = zeros(size(v))
for i in 1:size(v)
c = c + λ[i] * v[i]
end
return x
end
``````
1. The idea is to fit together many such vreps of different sizes/shapes in R3 in a given box without any overlaps so to simplify i start with R2 assuming the same should work in R3
``````va = [0 0;1 0 ;1 1 ;0 1 ] # a unit square
function get_nooverlap_constraint(m, n)
Am = ones(size(m))
An = ones(size(n))
return ((Am' * m) - (An' * n)) >= 1
end
a = vrep(va)
b = vrep(va)

p = minimize(norm(a + b))
# ensure none overlaps
``````a : [-0.45427274477738133 -0.45418622832194044; 0.2049041263858669 0.20490966184077403; 1.0444644866772845 1.0443668979909329; 0.2049041263168114 0.20490966190984883]