|
-
Nov 6th, 2007, 06:31 AM
#1
Thread Starter
New Member
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.
-
Nov 6th, 2007, 06:36 AM
#2
Fanatic Member
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.
-
Nov 7th, 2007, 10:19 AM
#3
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:
Private Function test()
Dim x As Double
Dim y As Double
Dim z As Double
Dim x0 As Double
Dim y0 As Double
Dim z0 As Double
Dim r As Integer
Dim i As Integer
Dim str As String
r = [A1].Value 'Put the desired radius in this cell before hitting F5
x0 = [A2].Value 'x-coordinate of centre
y0 = [A3].Value 'y-coordinate of centre
z0 = [A4].Value 'z-coordinate of centre
i = 1
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
For y = -r To r Step 0.5 'and defined by your steps
For z = -r To r Step 0.5
If (x - x0) ^ 2 + (y - y0) ^ 2 + (z - z0) ^ 2 = r ^ 2 Then
Range("B" & i) = "(" & x & "," & y & "," & z & ")" 'Outputs the coordinates to cells if they lie on the boundary of the sphere, essentially mapping the sphere
i = i + 1
End If
Next
Next
Next
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|