0

I have the co-ordinates of a rectangle. How can I draw a cube with this in C#?

graphics.drawRectangle(Pens.Black, x, y, width, height);

Rectangle has four co-ordinates but a cube has 8 co-ordinates. How can I locate the other four points of the rectangle to make it look like a cube.

When drawing a cube by hand from a rectangle, we need three-dimensions length X width X height. We will use an angle of 60 to 70 degree (approx) from X axis to draw z-axis and it will look like 3D. Similarly, we can draw length dimension for the rectangle and locate the point (x',y') for second rectangle. We will use the same height and width for the second rectangle and joining the two rectangles will give the cube.

I'm trying to do this in C#. To do this I need a co-ordinate of the second rectangle which is at an arbitrary distance (say 50) at an angle of 70 degree (approx) from (x, y) of first rectangle

7
  • 2
    There's no way a rectangle could turn into a cube, at least from where I see it. Do you mean a parallelepiped ? And to turn it into a 3D form, you'll need to add 3rd dimension, so I don't understand your question. Commented Apr 15, 2014 at 10:10
  • If you need a cube then you can draw 2 rectangle in different co-ordinate and connect them with line. school level concept as you draw using pen and paper. Commented Apr 15, 2014 at 10:13
  • @Bartdude, Thanks for your reply. I'll edit my question to be more clear. Commented Apr 15, 2014 at 10:16
  • @Rezoan, This is what I'm asking, how can I calculate the co-ordinates of the second rectangle? Commented Apr 15, 2014 at 10:17
  • 1
    make the 2 rectangle size same. Now draw first rectangle and and then draw the second rectangle by increasing the Y coordinate and decreasing the X coordinate of first rectangle. size and point depends on you that how you want to look it like. Commented Apr 15, 2014 at 10:22

2 Answers 2

1

There are many ways to draw a cube but a rectangle will always be a rectangle. You cannot add points to it (it would not be a rectangle anymore).

Have a look at this article It shows you one way to draw a cube.

If you are willing to have a less sophisticated way you might transform (skew) 2 or 3 rectangles and turn them into a projection of a cube.

Sign up to request clarification or add additional context in comments.

Comments

1

Here's a cheap hack for a filled cube (not wireframe), you can modify the way the 'i' part works to change the "perspective"

//draw the sides of the cube black
for (int i=-10;x<0;i++)
     graphics.drawRectangle(Pens.Black, x+i, y+i, width, height);
//draw the front of the cube red
graphics.fillRectangle(Brushes.Red, x, y, width, height);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.