Reputation: 53
I am trying to randomly generate points along the curved surface of a cylinder that has a y up-axis. Following a SO question of creating points along a 2D circle, I have
def point(h, k, r):
theta = random.random() * 2 * pi
global x
global y
x = h + cos(theta) * r
y = k + sin(theta) * r
given the cylinder's (h,k) origin point (0, -21.56462) and r (radius = 7.625). I then made these points 3D by generating a z point within my range (-2.35, 12.31). However, this got me half the way there because the final result was a cylinder but rotated 90 degrees clockwise.
What formula can I use that will generate the points in the correct direction? I am not that familiar with trigonometry, unfortunately. Thanks in advance!
THE SOLUTION:
def point(h, k, r):
theta = random.random() * 2 * pi
global x
global z
x = h + cos(theta) * r
z = k + sin(theta) * r
The new (h,k) origin is now (x,z) where x and z are the coordinates for the center of the cylinder and y is randomly generated within its appropriate height range. The vector is still (x,y,z).
Upvotes: 0
Views: 600
Reputation: 53
THE SOLUTION:
(thanks to David Huculak)
def point(h, k, r):
theta = random.random() * 2 * pi
global x
global z
x = h + cos(theta) * r
z = k + sin(theta) * r
The new (h,k) origin is now (x,z) where x and z are the coordinates for the center of the cylinder and y is randomly generated within its appropriate height range. The vector is still (x,y,z).
Upvotes: 1