Drawing regular polygons

Hi.

I’ve been trying for some time to draw regular polygons in openframeworks using the ofVertex function. I suppose this is much more a mathematical question than a programming one but i’m trying to get my head round cartesian co-ordinates and calculating angels.

Could somebody point me in the direction of some good documentation or suggest a better method of constructing simple shapes.

Thanks

I’ve found it helps to think on paper (graph paper) or to try drawing a program like photoshop, where you can open up an info window and see what the coordinate / pixels are that you want.

alternatively, if you throw this print out in to the mouse pressed function:

  
void testApp::mousePressed(int x, int y, int button){  
  printf("mouse pressed at %i %i \n", x,y);  
}  

you can click anywhere on the screen and then in the console (pops up on pc apps, command shift-r on mac) you can see where you’ve clicked. for example, it’s helpful if you want to position things on screen or get a feel for how the coordinate system works.

take care,
zach

Having finally got my head round Cartesian co-ordinates i’m now starting to think that there is an issue with cos and sin functions in C.

when calcuating Radius * Cos(90) the result is close to 0 but in C++ it draw this point quite far out from 0.

Has anyone experienced similar issues?

note that sin() and cos() take angles in radians, ie 0-two pi, as opposed to 0-360.

http://www.cplusplus.com/reference/clibrary/cmath/sin/

so, when you write cos(90), I think you might mean cos(PI/2.0) ?

does that help?

take care,
zach

indeed it does!

Shortly after my last post i realised my error and all was resolved!

Sorry to ask more questions but i’m now having trouble restricting the position of a circle with in the shape. The circle’s position is directly related to my mouse X Y position I’ve calculated how to restrict the mouse when the shape is square, triangle, and a straight line but the more complex shapes are really difficult to program.

I was think the code should basically say if the sum of mouse x and y can not be greater than a certain value so that when it reaches the side of a shape it begins subtracting any increase in y from x and vice cersa.

Any suggestions to how i could go about doing that?