# Manipulate a polygon

I am an absolute beginner in Mathematica. For a small test project, I am supposed to change the following code such that the corners of the polygon {0, 0, 0}, {1, 1, 1}, {0, 1, 0}, {1, 0, 1} can be manipulated. I did not find any satisfactory solution so far.

Manipulate[
Graphics3D[
Polygon[{{0, 0, 0}, {1, 1, 1}, {0, 1, 0}, {1, 0, 1}},
VertexColors -> {a, b, c, d}],
ImageSize -> {600, 600}],
{{a, Red, "first corner"}, Red},
{{b, Green, "second corner"}, Green},
{{c, Blue, "third corner"}, Blue},
{{d, Yellow, "fourth corner"}, Yellow}]

• What kind of manipulation to have in mind? What action should change invoke in the displayed polygon? Is it the position of the corners, or something else? Apr 17, 2018 at 18:16

Depending on how you want to manipulate the corners, you could do it a few ways.

1. Inputting points as a list

Manipulate[
Graphics3D[Polygon[{p1, p2, p3, p4}, VertexColors -> {a, b, c, d}],
ImageSize -> {600, 600}], {{a, Red, "first corner"},
Red}, {{b, Green, "second corner"},
Green}, {{c, Blue, "third corner"},
Blue}, {{d, Yellow, "fourth corner"}, Yellow},
Column[{Control[{{p1, {0, 0, 0}}}], Control[{{p2, {1, 1, 1}}}],
Control[{{p3, {0, 1, 0}}}], Control[{{p4, {1, 0, 1}}}]}]]


Output:

1b. Prettier version of 1:

Manipulate[
Graphics3D[Polygon[{p1, p2, p3, p4}, VertexColors -> {a, b, c, d}],
ImageSize -> {600, 600}], {{a, Red, "first corner"},
Red}, {{b, Green, "second corner"},
Green}, {{c, Blue, "third corner"},
Blue}, {{d, Yellow, "fourth corner"}, Yellow},
Control[{{p1, {0, 0, 0}}}], Control[{{p2, {1, 1, 1}}}],
Control[{{p3, {0, 1, 0}}}], Control[{{p4, {1, 0, 1}}}]]


Output:

1. User could use sliders to slide the corners

Manipulate[ Graphics3D[ Polygon[{{p1x, p1y, p1z}, {p2x, p2y, p2z}, {p3x, p3y, p3z}, {p4x, p4y, p4z}}, VertexColors -> {a, b, c, d}], ImageSize -> {600, 600}], {{a, Red, "first corner"}, Red}, {{b, Green, "second corner"}, Green}, {{c, Blue, "third corner"}, Blue}, {{d, Yellow, "fourth corner"}, Yellow}, Grid[{ {Control[{p1x, 0, 1}], Control[{p1y, 0, 1}], Control[{p1z, 0, 1}]}, {Control[{p2x, 0, 1}], Control[{p2y, 0, 1}], Control[{p2z, 0, 1}]}, {Control[{p3x, 0, 1}], Control[{p3y, 0, 1}], Control[{p3z, 0, 1}]}, {Control[{p4x, 0, 1}], Control[{p4y, 0, 1}], Control[{p4z, 0, 1}]}}]]

Output:

• thats exactly what I was looking for. Thank you! Apr 17, 2018 at 17:00
• You're welcome! Make sure to mark this as the correct answer if it was sufficient!! Apr 17, 2018 at 19:58