I have 2 sets, $X$ and $Y$. How do I find the Minkowski sum of these sets?
2 Answers
$\begingroup$
$\endgroup$
Another way is with Tuples
and Total
.
A = {1, 2, 3};
B = {a, b, c};
MinkowskiSum[lis__] := Total[Tuples[{lis}], {2}]
MinkowskiSum[A, B]
{a+1, b+1, c+1, a+2, b+2, c+2, a+3, b+3, c+3}
A1 = {1, 2};
A2 = {a, b};
A3 = {x, y};
MinkowskiSum[A1, A2, A3]
{a+x+1, a+y+1, b+x+1, b+y+1, a+x+2, a+y+2, b+x+2, b+y+2}
$\begingroup$
$\endgroup$
4
For example
x = {{1, 0}, {0, 1}, {0, -1}};
y = {{0, 0}, {1, 1}, {1, -1}};
Union @@ Outer[Plus, x, y, 1]
{{0, -1}, {0, 1}, {1, -2}, {1, 0}, {1, 2}, {2, -1}, {2, 1}}
You can use CirclePlus (⊕)
(entered as \[CirclePlus] or Escc+Esc) to define your Minkowski sum:
CirclePlus[x__] := Flatten[Union @@ Outer[Plus, x, 1], Length@{x} - 2]
x⊕y
{{0, -1}, {0, 1}, {1, -2}, {1, 0}, {1, 2}, {2, -1}, {2, 1}}
{{1,2}}⊕{{a,b}}⊕{{c,d}}
{{1 + a + c, 2 + b + d}}
-
$\begingroup$ How come it doesn't work with this problem? :( projecteuler.net/problem=228 I made two sets: s[3]={{1/2, Sqrt[3]/2}, {-1, 0}, {1/2, -(Sqrt[3]/2)}}; s[4]={{1/Sqrt[2], 1/Sqrt[2]}, {-(1/Sqrt[2]), 1/Sqrt[2]}, {-(1/Sqrt[2]), -(1/Sqrt[2])}, {1/Sqrt[2], -(1/Sqrt[2])}} But when I did Graphics[{Green, Polygon[s[3][CirclePlus]s[4]]}], I got something super crazy. Though now that I look at the overall shape, I feel like the outermost 6 points could result in the same shape as in the problem, but for some reason it's filled in a really strange way. $\endgroup$– RakshaCommented Mar 30, 2015 at 19:26
-
$\begingroup$ @Solarmew Use
Point
instead ofPolygon
to see that it does work and useLine
to see why yourPolygon
doesn't have the expected shape. $\endgroup$– Karsten7Commented Mar 30, 2015 at 19:53 -
$\begingroup$ I see. That's what I suspected. Is there a way to actually get the needed filled shape? Though even at that point, I'm not entirely sure how I'm gonna extract the number of sides from it %\ ... $\endgroup$– RakshaCommented Mar 30, 2015 at 20:34
-
1$\begingroup$ @Solarmew you might be looking for
ConvexHullMesh
and Region Properties and Measures. $\endgroup$– Karsten7Commented Mar 30, 2015 at 20:36
Join @@ Outer[Plus, X, Y, 1]
? Not sure if one shouldUnion
at the end, is this what you need? $\endgroup$