-6

I'm using Windows visual studio 2015 winforms to draw rectangles on a panel. I get my information from a list of objects(bricks). I just check the rotation for each brick:

My brick holds the following information:

    string ID;
    PointF MiddlePoint;
    float Length;
    float Height;
    float Rotation;

Creating the rectangle with a 90/270 angle of degree.

if (a_BrickList[i].Rotation == 90 || a_BrickList[i].Rotation == 270)
{
      UpperLeftPoint.X = Xorigin + (a_BrickList[i].MiddlePoint.X - (a_BrickList[i].Length / 2) + panelOffset) * scale;
      UpperLeftPoint.Y = Yorigin - (a_BrickList[i].MiddlePoint.Y + (a_BrickList[i].Height / 2) + panelOffset) * scale;
      rect = new RectangleF(UpperLeftPoint.X, UpperLeftPoint.Y, Length, Height);
      GlueRectangles[i] = rect;
}

I've added another if statement:

 if (a_BrickList[i].Rotation != 0 && a_BrickList[i].Rotation != 180 &&
     a_BrickList[i].Rotation != 90 && a_BrickList[i].Rotation != 270)

In this one I want to draw a rectangle on a certain angle of degree. But I can't really find anything about the rectangle with rotate or angle.

So is there a way to draw a rectangle with a certain angle of degree?

Or can I only solve this by calculating the 4 points of my rectangle and draw lines between them?

Bart
  • 717
  • 1
  • 9
  • 28

1 Answers1

1

It depends on the drawing environment you're using.

For example, if you use HTML5 canvas, you could rotate the canvas, draw the rectangle and then return the canvas to the original position, obtaining the "rotated" rectangle.

You should check your environment documentation for further info or give more info in the question so we can help you.

Bardo
  • 2,470
  • 2
  • 24
  • 42