I\'m trying to generate a spiral galaxy in the form of xy (2D) coordinates -- but math is not my strong suit.
I\'ve gleaned the following from an excellent source on spi
// a is 5 here
function x($t){ return 5 * $t * cos($t); }
function y($t){ return 5 * $t * sin($t); }
for ($t = 0; $t < 50; $t += 0.01) {
$xyPoint = array(x($t), y($t));
// draw it
}
when you encounter parametric equations like this, its common for the parameter variable to be t
, which means time. So you could think of plugging increasing values of t into the functions, and getting coordinates which gradually change as elapsed time increases.
you'll need to choose your own values for a, the range of t, and the increment step size of t. It just depends on your requirements. both cos() and sin() have a max value of 1, if that helps you figure out suitable values for a and t depending on your canvas size