1
$\begingroup$

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[[1]] - tam1/2, pos1[[2]]}, {pos1[[1]] + tam1/2, 
      pos1[[2]] + tam1}]}];

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

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

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

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

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

enter image description here

$\endgroup$
  • $\begingroup$ What exactly do you need? $\endgroup$ – LCarvalho Sep 26 '16 at 17:15
2
$\begingroup$

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[[1]], 
     position[[2]] - tam/2}, {position[[1]] + tam, 
     position[[2]] + 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]
$\endgroup$
  • $\begingroup$ Yes it would be that the idea. But it is not right your code. It is with some failure. $\endgroup$ – JPeter Sep 27 '16 at 11:59
  • $\begingroup$ Has an error. I am still trying to figure out where. $\endgroup$ – LCarvalho Sep 27 '16 at 12:04
  • $\begingroup$ I did one modification $\endgroup$ – LCarvalho Sep 27 '16 at 12:27
  • $\begingroup$ And as to the point, what can be done? $\endgroup$ – JPeter Sep 27 '16 at 12:30
  • 2
    $\begingroup$ 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. $\endgroup$ – Michael E2 Sep 27 '16 at 12:58
3
$\begingroup$

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[[1]] - tam1/2, pos1[[2]], pos1[[1]] + tam1/2, pos1[[2]] + tam1}, Blue];
g2 = g[{pos2[[1]] - tam2, pos2[[2]] - tam2/2, pos2[[1]], pos2[[2]] + tam2/2}, Green];
g3 = g[{pos3[[1]] - tam1/2, pos3[[2]] - tam1, pos3[[1]] + tam1/2, pos3[[2]]}, Blue];
g4 = g[{pos4[[1]], pos4[[2]] - tam2/2, pos4[[1]] + tam2, pos4[[2]] + 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.

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

" ... 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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Michael E2 Sep 27 '16 at 12:28

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.