#### Archived

This topic is now archived and is closed to further replies.

# Circle Drawing

This topic is 5973 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a vertex buffer (triangle strip), and it looks like a line on the screen. I''d like to take the x and y axis of one of the vertices, and make it fan out, while the other side stays still. I''m having trouble calculating what I should transform the cartesian coordinates to though. I know x = r cos T , y= r sin T, but that doesn''t seem to be enough. Thanks.

##### Share on other sites
Is this in 3D or 2D ? Correct me if I''m wrong, but if I understand you correctly you want to rotate a point around the center of the fan right ?

If you want to rotate a point in 2D you can do like this:

  void rotPoint(float &x, float &y, float angle){ // if the angle is in degrees, convert it to radians: angle = (angle / 180.0f) * PI; // assigning them to some temporary variables float tx = x; float ty = y; // calculating the new position x = (tx*cos(angle)) - (ty*sin(angle)); y = (tx*sin(angle)) + (ty*cos(angle));}

To rotate a point about an axis in 3D its a bit more complicated, if that is what you want to do, just ask

My post up, your post down, my site here

##### Share on other sites
It is rather confusing as to exactly what you are trying to do. If you number your vertices starting at zero then all the even ones have to be translated to the position of the first one, i.e. vertex zero. In other words set them all to be equal to the first point. The odd ones have to be rotated according to their distance from the first vertex. If the distance to the last odd vertex is D and the distant to a given vertex is d then the angle T is 2*d*pi/D. That is the T from your equation. In your equation r is the radius of the desired circle. You are missing a term on each though. It should be x=r*cos(t)+cx and y=r*sin(t)+cy. The (cx,cy) is the x and y components of the first vertex. Assuming all the vertices have the same z then if you don''t change the z you will get a circle in a plane parallel to the xy plane. Since every other vertex is the same a triangle fan makes more sense than a triangle strip. A triangle strip forms triangles from the last three vertices. A triangle fan forms them from the last two plus the first one.

Overall it would make more sense just to generate a fan directly. I suppose it could make a rather cool animation though.

##### Share on other sites
This is in 2D. So I''ve constructed a function basically like the one prescribed above, but I''ve still got a few questions. First, shouldn''t I update the angle every run through in order to rotate the point? And second, when I use the function as is, I''m getting sort of two things happening at once. The vertex does seem to be rotating downward, but there is sort of a "ghost" of the image which is shooting up and to the left.

• 10
• 9
• 48
• 12
• 10
• ### Forum Statistics

• Total Topics
631385
• Total Posts
2999705
×