Draw a point a set distance away from a base point
Asked Answered
R

3

5

I'm trying to figure out an algorithm for finding a random point a set distance away from a base point. So for example:

alt text

This could just be basic maths and my brain not working yet (forgive me, haven't had my coffee yet :) ), but I've been trying to work this out on paper and I'm not getting anywhere.

Rinee answered 5/8, 2010 at 12:22 Comment(0)
N
10

coordinate of point on circle with radius R and center (xc, yc):

x = xc + R*cos(a);
y = yc + R*sin(a);

changing value of angle a from 0 to 2*PI you can find any point on circumference.

Newmarket answered 5/8, 2010 at 12:25 Comment(0)
M
5

Use the angle from the verticle as your random input.

Pseudocode:

angle = rand(0,1)
x = cos(angle * 2 * pi) * Radius + x_centre
y = sin(angle * 2 * pi) * Radius + y_centre
Megdal answered 5/8, 2010 at 12:28 Comment(0)
G
1

Basic Pythagoras.

Pick random number between 0 and 50 and solve h^2 = a^2 + b^2 Add a few random descisions on direction.

Galvanotropism answered 5/8, 2010 at 12:26 Comment(2)
It should be pointed out that this will not give an answer that's uniformly distributed in the way most people would expect. Instead, this method (used, say, on the unit circle) will tend to slightly favour points near (1,0) and (-1,0) (or (0,1) and (0,-1) depending on how you implement it).Osmometer
@Peter - Good point. And the density, I believe, should be sin() or cos().Unfrock

© 2022 - 2024 — McMap. All rights reserved.