Originally posted by Shyam Murarka:
Dear Readers,
Ryan, thanks a million for those pieces of code. Now I seem to be thinking was it really that simple? Anyways, I think I wanted the first piece of code at first but after looking at the second code I thought why not actually do it this way, because even Ovals are bounded inside a Rectangle.
Typically, geometric problems like this can take use of some basic mathematics. In the future, I suggest that you get out some graph paper and draw things out by hand. Then try to figure out if there are any mathematical forumlae that will help simplify things.
For instance, in code Ryan gave above, he realized that the vertices for the diamond are half way between the vertices of the bounding box. I'm not entirely sure what the line "x -= (x2-x1);" is for. I think I could draw the diamond without doing that:
Note that I haven't tested this code, so I'm only 90% confident that it works. I figured this out by labeling the vertices of the bounding rectangle described by (x1, y1) and (x2, y2) and the vertices of the diamond. This makes it so you can just calculate the necessary values for x and y in the code above and then draw 4 lines.
HTH
Layne