Programmers of any language... need help

Discussion in 'OT Technology' started by kcarlson78, Apr 17, 2003.

  1. kcarlson78

    kcarlson78 Meanwhile, Jesus continued to shake his head in ex

    Joined:
    Jun 27, 2002
    Messages:
    4,490
    Likes Received:
    0
    Location:
    Phoenix, AZ
    Ok.. this isn't language specific... I need an algorithm for plotting points on a circle given the center point (x,y) and the radius r, how do i generate a couple coordinates (x1,y1) pairs around the circle?

    [​IMG]

    I'm writing a fireworks applet in java.. and it's all done.. except when my fireworks explode.. they're square.. I'd kinda like 'em to be round..

    :confused: I soo feel like I should know this.. but can't seem to bring the information to the surface of my brain right now..

    incase you're interested.. the project is here:
    http://www.ourvillageidiots.com/fireworks/
     
  2. Early Apex

    Early Apex Guest

    Okay, I think I've got it. Code below is Excel VBA, but can easily be adapted to any language.

    To determine the x- and y-coordinates, use these formulas:

    [​IMG]
    [​IMG]

    Where:

    r = radius
    q = qth point of n
    n = total number of points
    j = circle center, x-axis
    k = circel center, y-axis
    Xq = x-coordinate for qth point
    Yq = y-coordinate for qth point

    The code in Excel VBA looks like this (I didn't clean up any of the parens...)

    Code:
    Sub MakeACircle()
        Dim n As Double
        Dim x As Double
        Dim y As Double
        Dim j As Double
        Dim k As Double
        Dim r As Double
        Dim q As Integer
        
        r = 2
        j = 5
        k = 5
        
        'This number controls gow many points the circle has
        n = 30
        
        For q = 1 To n
            x = (r * (Cos(((q * 3.1415926535 * 360) / n) / 180))) + j
            y = (r * (Sin(((q * 3.1415926535 * 360) / n) / 180))) + k
            
            Cells(q + 1, 1) = x
            Cells(q + 1, 2) = y
        Next q
        
    End Sub
    
    The output, and a graph of it, looks like this:
    [​IMG]

    Hope that helps!
     
  3. kcarlson78

    kcarlson78 Meanwhile, Jesus continued to shake his head in ex

    Joined:
    Jun 27, 2002
    Messages:
    4,490
    Likes Received:
    0
    Location:
    Phoenix, AZ
    Ha!! You are a prince among men.. thank you.. :bowdown:

    I now have nice little circle fireworks.. :big grin:
     

Share This Page