遍历描述螺旋的公式以生成XY坐标 [英] Looping through a formula that describes a spiral to generate XY coordinates

查看:142
本文介绍了遍历描述螺旋的公式以生成XY坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成xy(2D)坐标形式的螺旋星系-但是数学并不是我的强项.

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 spirals:

半径r(t)与角度t成正比 最简单的螺旋,阿基米德的螺旋.因此,等式为:

The radius r(t) and the angle t are proportional for the simpliest spiral, the spiral of Archimedes. Therefore the equation is:

(3)极坐标方程:r(t)= at [a为常数].
从此开始
(2)参数形式:x(t)=等于cos(t),y(t)=等于sin(t),
(1)中环 等式:x²+y²=a²[弧形tan(y/x)]².

(3) Polar equation: r(t) = at [a is constant].
From this follows
(2) Parameter form: x(t) = at cos(t), y(t) = at sin(t),
(1) Central equation: x²+y² = a²[arc tan (y/x)]².

这个问题有点涉及星系的产生,但是对于我所需要的,答案是分散的,但仍然过于复杂(aka,我的数学笨拙的头脑无法理解它们).

This question sort of touched upon galaxy generation, but the responses were scattered and still overly complex for what I need (aka, my math-dumb mind can't understand them).

基本上,我需要做的是在PHP中循环遍历一个螺旋公式〜5000次,以在513x513 XY网格上生成点.网格的大小和所需的点数将来可能会更改.更好的办法是权衡这些点的频率和螺旋线的起点,使其偏离频率的精确度,以及它们可能偏离确切的数学公式的距离,这与银河的实际外观类似.

Essentially, what I need to do is loop through a spiral formula in PHP ~5000 times to generate points on a 513x513 XY grid. The size of the grid and the number of points needed may change in the future. Even better would be to weigh those points towards the origin of the spirals both in frequency and how far they can stray from the exact mathematical formula, similarly to how a galaxy actually looks.

此数学论文讨论了描述螺旋星系结构的公式.

让我完全迷失的是如何将数学公式转换为可以在PHP中循环的东西!

What completely loses me is how to translate a mathematical formula to something I can loop through in PHP!

推荐答案

// 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
}

当您遇到这样的参数方程式时,参数变量通常为t,即时间.因此,您可以考虑将递增的t值插入函数,并获得随着经过时间的增加而逐渐变化的坐标.

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.

您需要为a,t的范围和t的增量步长选择自己的值.这仅取决于您的要求. cos()和sin()的最大值都为1,如果这可以帮助您根据画布大小为a和t找出合适的值

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

这篇关于遍历描述螺旋的公式以生成XY坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆