3
$\begingroup$

I have 2 sets, $X$ and $Y$. How do I find the Minkowski sum of these sets?

$\endgroup$
2
  • 3
    $\begingroup$ according to wikipedia: Join @@ Outer[Plus, X, Y, 1]? Not sure if one should Union at the end, is this what you need? $\endgroup$ – Kuba Mar 4 '15 at 21:06
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey Mar 4 '15 at 21:10
5
$\begingroup$

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}
$\endgroup$
3
$\begingroup$

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}}
$\endgroup$
4
  • $\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$ – Raksha Mar 30 '15 at 19:26
  • $\begingroup$ @Solarmew Use Point instead of Polygon to see that it does work and use Line to see why your Polygon doesn't have the expected shape. $\endgroup$ – Karsten 7. Mar 30 '15 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$ – Raksha Mar 30 '15 at 20:34
  • 1
    $\begingroup$ @Solarmew you might be looking for ConvexHullMesh and Region Properties and Measures. $\endgroup$ – Karsten 7. Mar 30 '15 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.