# Creating a graphic with four rectangles and four points

I created a graphic with four rectangles and four points. The rectangles has a way itself to be created. It is possible to place the rectangles in function of the points

pos1 = {0, 1};
pos2 = {-1, 0};
pos3 = {0, -1};
pos4 = {1, 0};
tam1 = 1;
tam2 = 1.5;

g1 = Graphics[{Blue,
Rectangle[{pos1[] - tam1/2, pos1[]}, {pos1[] + tam1/2,
pos1[] + tam1}]}];

g2 = Graphics[{Green,
Rectangle[{pos2[] - tam2, pos2[] - tam2/2}, {pos2[],
pos2[] + tam2/2}]}];

g3 = Graphics[{Blue,
Rectangle[{pos3[] - tam1/2,
pos3[] - tam1}, {pos3[] + tam1/2, pos3[]}]}];

g4 = Graphics[{Green,
Rectangle[{pos4[], pos4[] - tam2/2}, {pos4[] + tam2,
pos4[] + tam2/2}]}];

points = Graphics[{Red, PointSize[0.02], Point[pos1], Point[pos2],
Point[pos3], Point[pos4]}];

Show[g1, g2, g3, g4, points] • What exactly do you need? – LCarvalho Sep 26 '16 at 17:15

Need modification, but this is the idea.

pos1 = {0, 1};
pos2 = {-1, 0};
pos3 = {0, -1};
pos4 = {1, 0};
tam1 = 1;
tam2 = 1.5;
zero = Graphics[{PointSize[0.01], Point[{0, 0}]}];

rect[position_, tam_, color_] := {color,
Rectangle[{position[],
position[] - tam/2}, {position[] + tam,
position[] + tam/2}], Red, PointSize[0.035], Point[position]};

g1 = Graphics[GeometricTransformation[
rect[pos1, tam1, Blue],
RotationTransform[Pi/2, pos1]
]];
g2 = Graphics[GeometricTransformation[
rect[pos2, tam2, Green],
RotationTransform[Pi, pos2]
]];
g3 = Graphics[GeometricTransformation[
rect[pos3, tam1, Blue],
RotationTransform[3 Pi/2, pos3]
]];
g4 = Graphics[GeometricTransformation[
rect[pos4, tam2, Green],
RotationTransform[0, pos4]
]];

Show[g1, g2, g3, g4, zero]

• Yes it would be that the idea. But it is not right your code. It is with some failure. – JPeter Sep 27 '16 at 11:59
• Has an error. I am still trying to figure out where. – LCarvalho Sep 27 '16 at 12:04
• I did one modification – LCarvalho Sep 27 '16 at 12:27
• And as to the point, what can be done? – JPeter Sep 27 '16 at 12:30
• Re other edits: I wish you wouldn't make so many trivial improvements to old posts every day. It makes the site more difficult to use. Perhaps you could limit yourself to five per day or per 12 hours. – Michael E2 Sep 27 '16 at 12:58

If I understand correctly your question, this should do the trick:

g[{pos1_, pos2_, pos3_, pos4_}, color_] := Graphics[{color, Rectangle[{pos1, pos2}, {pos3, pos4}]}]


To be used as:

g1 = g[{pos1[] - tam1/2, pos1[], pos1[] + tam1/2, pos1[] + tam1}, Blue];
g2 = g[{pos2[] - tam2, pos2[] - tam2/2, pos2[], pos2[] + tam2/2}, Green];
g3 = g[{pos3[] - tam1/2, pos3[] - tam1, pos3[] + tam1/2, pos3[]}, Blue];
g4 = g[{pos4[], pos4[] - tam2/2, pos4[] + tam2, pos4[] + tam2/2}, Green];


This does not seem really simpler but you did not give additional details to program an efficient function.

You could also add a red point in the definition of g.

• @corey979 Thanks. I do not have privileges to edit with less than 6 words. – LCarvalho Sep 26 '16 at 15:07

" ... is possible to place the rectangles in function of the points"

The short answer is - no, you cannot use a type Rectangle as an input to function Point.

Following is a set of Point signatures

Point[p] is a graphics and geometry primitive that represents a point at p.
Point[{p1, p2,...}] represents a collection of points.

• I think perhaps the OP's English does not quite accurately represent the thought: My guess is that the OP wants the rectangle to be a function of the coordinates of the points, which is certainly possible. – Michael E2 Sep 27 '16 at 12:28