Thread: Best way to draw circle!!??

  1. #1

    Best way to draw circle!!??

    I'm creating mod's for this game and I need to know some things about 3D math...

    TRIGONOMETRY

    namely, the best way to draw a CIRCLE in a 3D game --

    Is it just a rotation about the X axis?? or is there a better way..
    If it is a rotation can u give me the best way as I would have to create a loop and calculate for 360 degrees or do I have to even do more than 360 calculations to make it more beleivable??

    These links will help what I'm talking about -- the 2nd deals more with the actual game im working with.

    Basic 3D math
    http://toadlife.net/ofp/downloads/tu...trigguide.html
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    well, a circle isn't a 3D shape. If you want to impose a circle on top of the display, then do the thing with the for loop. The number of steps you'll need depends on the size of the circle. If you want the circle in the world...make a model with a bunch of points in the shape of a circle or something.
    Away.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    So we can use Polar coordinates to find the points on a circle given a distance from origin.

    We can then convert to rectangular coordinates as follows:

    x = r * cos( theta )
    y = r * sin( theta )

    Where r is the radius of the desired circle and theta is the angle.
    (x,y) will be your point on the given circle.

  4. #4
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    Brensenham's (spelling?) circle (and line too) algorithm is quite effective, but since you'd need to scale it for perspective maybe it wouldn't be as effective.
    hasafraggin shizigishin oppashigger...

  5. #5
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    If you want to make a CIRCLE, you can use the Borlan graphics library.

  6. #6
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    If You were using Opengl You needed only one function
    &one header.

    header GLAUX.H
    function auxSolidSphere(float);



    // rotation speed
    if (angle >= 359.0f)
    angle = 0.0f;
    angle += 0.2;
    Last edited by SAMSAM; 04-27-2003 at 07:12 PM.

  7. #7
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    like this; 3 balls with a blending & lighting mix.
    Last edited by SAMSAM; 04-27-2003 at 07:28 PM.

  8. #8
    Ok,

    Thanx for all the advice but I think only MrWizard got what I was trying to ask - for any standard shapes I will be using a graphics library like OpenGl or DX but this is more about formulas/algorithim's to produce the shapes.

    I'm working in GAME SCRIPT and don't have the luxury of standard function calls to produce my affects.

    I was thinking that I will have to create a circle using the formula
    x = r * cos( theta )
    y = r * sin( theta )
    , check the 2nd link in my first post to understand this formula.

    Using the above formula I will have to create a loop and calculate at least 360times to get the 360 degree values to produce a 2D(x,y) circle -- im not really after a 3D sphere shape.

    I wanna know if there is a better formula or just better way to work the above formula so I don't have to run through 360 loop cycles or even more to get 2D pts around my target to create a circular pattern?? For instance I know that there are quadrants I can work in when using degrees like 0-90, can I just run through the sin/cos calcs for 0-90 and somehow adjust the gotten values to and apply them to the next quadrant or is it just as fast to calculate 360 sin/cos values??

    Code:
    //Psuedo-code as im not working in C++
    targetPosition = <2341,3642,0> //3D Vector <x,y,z>
    
    /*I need to find points at every angle at 300meters from my 
    *target's position - the target's position will be the center of the 
    *circle and 300 meters is the radius
    *Formula r*cos(theta) - r stands for radius
    */
    //I only need the 2D coords
    A = 0;               //This is the angle - 0 - 360
    r = 300;           //This is the radius
    targetXPos= 2341;  //Targets X position
    targetYPos= 3642;  //Targets Y position
    
    #LOOP
    //In this loop we will calculate 360 times to get 360 points around our target
    for(A; A<=360;A++){
       x = cos(A) * r;
       y = sin(A) * r;
    
       newXPos= targetXPos + x;
       newYPos= targetYPos + y;
    }
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  9. #9
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    I'm glad you asked. You only need to do 1/4 of the circle then the other 3 are variations of your original points. Lets say one of your points in the upper right part of a unit circle with center at origin is:

    We go from 0 to 90 to get upper right portion.
    ( 45 degrees example )

    x = .99
    y = .707

    Then the upper left would be

    x = -.99
    y = .707

    Then lower left:

    x = -.99
    y = -.707

    Then lower right:

    x = .99
    y = -.707


    Looking for something like that?

  10. #10
    That's exactly correct - but sin/cos already do that I guess - the same values are repeated only in different order and neg values...

    sooooo not sure whether splitting it up would make up any time differences.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  11. #11
    Let's say I want to instead create a MATRIX 300 x 300 -- in game...

    This will play out like an animated-gif image so it's easy all i have is arrays filled with 2D vector points and the matrix is swapped over time so it plays as an animation..... simple.

    OK, how can I create this matrix and then be able to "PASTE" it in anywhere in my 3D world... the values in the matrix need to change according to where it's placed in game so I need advice on how to record the MATRIX values so they are easily changed.

    If I start at 0 on left hand side like a standard XY graph in my recorded MATRIX values, how do I change all the values in my MATRIX to correspond with a starting 2D vector of <2340,1355> on the left hand corner.

    ???

    PS--I think this method will be significantly faster than calculating each point using a loop...
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  12. #12
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    Even if you shorten the loop by segmentation(break it into
    pies) you still need an inner loop to figure out the x&y coordinates
    in relation to those, in order to save them in point[360] array.

    dont we?.

  13. #13
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    hey mr stiffy, test the time it takes to run each loop. Obviously running through the first quadrant and then setting points from there will be faster, but the other method will probably run so fast it won't really matter.

    DWORD begintime, totaltime;
    begintime = GetTickCount();

    for(a ridiculously high number of times)
    dostuff();

    totaltime = GetTickCount - BeginTime();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Half of the circle
    By hdragon in forum Game Programming
    Replies: 14
    Last Post: 03-10-2006, 10:15 PM
  2. Draw The Circle
    By rifatgunduz in forum C++ Programming
    Replies: 11
    Last Post: 01-26-2005, 06:49 AM
  3. Draw circle
    By Roaring_Tiger in forum C Programming
    Replies: 7
    Last Post: 09-30-2004, 07:16 PM
  4. Draw a circle?
    By TheShaggmeister in forum C++ Programming
    Replies: 6
    Last Post: 07-22-2003, 01:35 PM
  5. point lies in circle?
    By cozman in forum Game Programming
    Replies: 3
    Last Post: 12-20-2001, 04:39 PM