• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
MichaelBarth

[SOLVED]Triangular Rotation\Creating a "Circle" out of Triangles

5 posts in this topic

[Trigonometric Knowledge Useful!]

Alright, I'm trying to create my own version of a circle by using triangles, I guess right now my intended circle will be an octagon because it has 8 sides, well it will.

So far I have this one triangle:

[img]http://i610.photobucket.com/albums/tt190/Spirrwell/Screenshotfrom2012-11-16135637.png[/img]

The two sides on the left and right is known as r for radius which is equal to half of the window's height. Since I was going to try to deal with a circle with 8 "slices" the angle measure of the bottom angle has to be 45 degrees. and I use that to find the length of the top side which is done with this function:

[CODE]
double FindMissingSide(double a, double b, double C)
{
//ToRadians is a variable which is PI/180.0
double c = sqrt(pow(a, 2.0) + pow(b, 2.0) - 2 * a * b * cos(C * ToRadians));
return c;
}
[/CODE]


I use it in my drawing code (Yes I know I'm calculating the unknown side every time, but this is a small project so I'm not worried):

[CODE]
glPushMatrix();
glColor3f(1.0f, 1.0f, 1.0f);
glTranslated((double)ScreenWidth/2.0, (double)ScreenHeight/2.0, 0.0);
glBegin(GL_TRIANGLES);
glVertex2d(0.0 - (FindMissingSide(r, r, 360.0/slices)/2), 0.0 - r);
glVertex2d(0.0 + (FindMissingSide(r, r, 360.0/slices)/2), 0.0 - r);
glVertex2d(0.0, 0.0);
glEnd();
glPopMatrix();
[/CODE]

Now before I went and created a for loop, I decided I'd create another triangle and rotate 45 degrees with [i]glRotated(45.0, 0.0, 0.0, 1.0);[/i], which I would expect the two triangles to share one side, but it has a gap of about 3 degrees:

[img]http://i610.photobucket.com/albums/tt190/Spirrwell/Screenshotfrom2012-11-16135708.png[/img]

Now I said it seemed to have a gap of 3 degrees because if I set the x rotation to 42, it shares the side, but then it's off by 3 degrees, and the next triangle I would have to subtract 6 degrees because I already subtracted 3 from the last rotation.

I don't understand, I must be doing something plainly stupid and I don't see it. I would think that I must be calculating the missing side wrong somehow...

Any ideas?
0

Share this post


Link to post
Share on other sites
Wouldn't it be easier to just calculate where the vertices should be, instead of making triangles and rotating them? Then you'd have one vertex in the middle and the vertices in the outside - which you can calculate using sines and cosines (and a multiplication), no need for square root at all.

Unless there's some extra requirement here I'm missing.

EDIT: also that still wouldn't be the optimal solution since you can ditch the middle vertex and just make all the triangles touch one of the vertices in the outside (while also reducing triangle count in the process!), but then it wouldn't be split like pizza slices (which may or may not matter for your project). Edited by Sik_the_hedgehog
0

Share this post


Link to post
Share on other sites
Because I'm stupid and I don't know how. I actually haven't even learned trigonometric math, I had to teach myself some stuff because I'm still in high school in my first semester of geometry. I'm trying to teach myself how this works that's why I'm working on it the only way I know how. I mean I could do this using GLU\GLUT or whatever to take the easy way out, but I'm just trying to figure out it works.
0

Share this post


Link to post
Share on other sites
[quote]glVertex2d(0.0 - (FindMissingSide(r, r, 360.0/slices)/2), 0.0 - r);
glVertex2d(0.0 + (FindMissingSide(r, r, 360.0/slices)/2), 0.0 - r);[/quote]

I think your y values might be the problem.
Your y values are 0-0 - r (the circumRadius)
But what you want is 0-0 - h (the Apothem) - the height of the triangle in your case.

Where h is calculated using pythagoros as:
h = sqrt(pow(r, 2.0) + pow(FindMissingSide(r, r, 360.0/slices)/2, 2.0)

Wikipedia's got a good description of regular polygon's which I found pretty useful. http://en.wikipedia.org/wiki/Regular_polygon

Hope this works.

Matt
2

Share this post


Link to post
Share on other sites
Here's the algorithm I'm using to perform the same kind of thing you're doing but closer to the way suggested by #2 Sik_the_hedgehog. I've inlined some support methods so it's all in one place so hopefully it still works :).

(Java code)

[CODE]
public static Polygon createRegularPolygon(int numberOfSides,
double sideLength, double dblStartAngleInDegrees)
{
// slice angle
double dblSliceAngle = (2 * Math.PI) / numberOfSides;

// calculate circum radius
double dblRad = sideLength / (2 * Math.cos( (180 - dblSliceAngle) / 2);

// calculate the start angle in radians for repeated use in the for loop
double startAngleInRadians = Math.toRadians(dblStartAngleInDegrees);

// now define the polygon
for (int i = 0; i < numberOfSides; ++i)
{
double dblAngle = startAngleInRadians + (dblSliceAngle * i);
int x = (int) Math.round(Math.cos(dblAngle) * dblRad);
int y = (int) Math.round(Math.sin(dblAngle) * dblRad);

// store x and y somewhere for later use...
}
}
[/CODE]

Matt
0

Share this post


Link to post
Share on other sites
[quote name='de_mattT' timestamp='1353100774' post='5001640']
[quote]glVertex2d(0.0 - (FindMissingSide(r, r, 360.0/slices)/2), 0.0 - r);
glVertex2d(0.0 + (FindMissingSide(r, r, 360.0/slices)/2), 0.0 - r);[/quote]

I think your y values might be the problem.
Your y values are 0-0 - r (the circumRadius)
But what you want is 0-0 - h (the Apothem) - the height of the triangle in your case.

Where h is calculated using pythagoros as:
h = sqrt(pow(r, 2.0) + pow(FindMissingSide(r, r, 360.0/slices)/2, 2.0)

Wikipedia's got a good description of regular polygon's which I found pretty useful. [url="http://en.wikipedia.org/wiki/Regular_polygon"]http://en.wikipedia....Regular_polygon[/url]

Hope this works.

Matt
[/quote]

Thank you! I could've stared at my work for a year and probably never have noticed that. Since I was thinking circle I thought radius, which would be the same distance from the center in any direction, but because I'm using triangles, that's not true. I guess I accidentally created a faulty syllogism by thinking that way. Again thank you very much! Also, thank you for the extra information, although there was a bug in that one line you gave me: [i]h = sqrt(pow(r, 2.0) + pow(FindMissingSide(r, r, 360.0/slices)/2, 2.0) [/i]That plus sign should be a subtraction one. That's at least how I did it...
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0