Results 1 to 3 of 3

Thread: Drawing circle and sphere

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    2

    Drawing circle and sphere

    Sir,

    I need to draw a circle with a given center and radius.
    I want the points present in the circle with fixed angle.ex : 10 degrees.

    ex :
    consider center is (0,0) radius = 5;

    1st point is (0,5)
    2nd point is ?
    .
    .
    .
    .
    I need to get the points on the circle.



    question 2 :

    Consider a point in space ie 3D . I need to draw a sphere for a given radius.
    How to get the points.

  2. #2
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Drawing circle and sphere

    Let me be the first to welcome you to the forums!

    For question 1:

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

    Use fixed increments of theta in radians.

  3. #3
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Drawing circle and sphere

    Well the equation of a sphere with centre (x,y,z) is

    (x' - x)^2 + (y' - y)^2 + (z' - z)^2 = r2^2

    In order to get the points for a given radius, you could write a program something like this:

    vb Code:
    1. Private Function test()
    2.  
    3. Dim x As Double
    4. Dim y As Double
    5. Dim z As Double
    6. Dim x0 As Double
    7. Dim y0 As Double
    8. Dim z0 As Double
    9.  
    10. Dim r As Integer
    11. Dim i As Integer
    12.  
    13. Dim str As String
    14.  
    15.  
    16. r = [A1].Value  'Put the desired radius in this cell before hitting F5
    17. x0 = [A2].Value 'x-coordinate of centre
    18. y0 = [A3].Value 'y-coordinate of centre
    19. z0 = [A4].Value 'z-coordinate of centre
    20. i = 1
    21.  
    22. For x = -r To r Step 0.5      'This will loop through every possible combination of x, y and z values within the bounds of your radius
    23.     For y = -r To r Step 0.5  'and defined by your steps
    24.         For z = -r To r Step 0.5
    25.             If (x - x0) ^ 2 + (y - y0) ^ 2 + (z - z0) ^ 2 = r ^ 2 Then
    26.                 Range("B" & i) = "(" & x & "," & y & "," & z & ")"  'Outputs the coordinates to cells if they lie on the boundary of the sphere, essentially mapping the sphere
    27.                 i = i + 1
    28.             End If
    29.         Next
    30.     Next
    31. Next
    32.  
    33. End Function
    Last edited by MaximilianMayrhofer; Nov 7th, 2007 at 10:24 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width