문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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

Basic Pythagoras.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top