gpt4 book ai didi

php - 循环遍历描述螺旋的公式以生成 XY 坐标

转载 作者:可可西里 更新时间:2023-10-31 22:14:58 25 4
gpt4 key购买 nike

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

我从 excellent source 中收集了以下信息在螺旋上:

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

(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)]².

This question有点涉及星系生成,但响应是分散的,而且对于我需要的东西来说仍然过于复杂(也就是说,我的数学头脑无法理解它们)。

本质上,我需要做的是在 PHP 中循环使用螺旋公式约 5000 次,以在 513x513 XY 网格上生成点。网格的大小和所需的点数将来可能会发生变化。更好的办法是在频率和它们偏离精确数学公式的距离上权衡这些点对螺旋原点的影响,类似于星系的实际外观。

这篇数学论文讲的是a formula that describes the structure of spiral galaxies .

让我完全迷失的是如何将数学公式转换成我可以在 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 值插入到函数中,并获得随时间增加而逐渐变化的坐标。

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

关于php - 循环遍历描述螺旋的公式以生成 XY 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10874678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com