Angles/zh: Difference between revisions

From Minecraft Parkour Wiki
Content added Content deleted
(Created page with "static { for (int i = 0; i < 65536; ++i) { SIN_TABLE[i] = (float)Math.sin((double)i * Math.PI * 2.0D / 65536.0D); } } </syntaxhighlight>'''Note:''' ''<code...")
(Updating to match new version of source page)
 
(64 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
本文是[[Special:MyLanguage/Mouse Movement|鼠标运动]]的延续,重介绍三角函数在Minecraft中的工作原理。
本文是[[Special:MyLanguage/Mouse Movement|鼠标运动]]的延续,重介绍三角函数在 Minecraft 中的工作原理。




Line 6: Line 6:
玩家的'''偏航角'''是一个[http://zh.wiki.sxisa.org/wiki/%E6%B5%AE%E7%82%B9%E6%95%B0 浮点数],用于跟踪玩家的水平旋转(以度为单位)。它是'''无限的'''。
玩家的'''偏航角'''是一个[http://zh.wiki.sxisa.org/wiki/%E6%B5%AE%E7%82%B9%E6%95%B0 浮点数],用于跟踪玩家的水平旋转(以度为单位)。它是'''无限的'''。


玩家的'''朝向'''是将偏航角限制[-180°, 180°],如[[Special:MyLanguage/Debug Screen|F3]]所示。
玩家的'''朝向'''是将偏航角限制[-180°, 180°],如 [[Special:MyLanguage/Debug Screen|F3]] 所示。


'''有效角''',或者简单地说,'''角度'''是一个整数 (从 <math display="inline">0</math> 到 <math display="inline">2^{16}-1</math>)。
'''有效角''',或者简单地说,'''角度'''是一个整数(从 <math display="inline">0</math> 到 <math display="inline">2^{16}-1</math>)。




Line 14: Line 14:




<span id="Significant_Angles"></span>
== 有效角 ==
== 有效角 ==


Minecraft 的三角函数依赖于有效角,这意味着玩家的偏航角必须转换为一个角度。
Minecraft 的三角函数依赖于有效角,玩家的偏航角必须转换为一个具体角度。


<div class="mw-translate-fuzzy">
这种转换会导致不精准:一个有效角跨越 ~<math>0.0055°</math>).
这种转换导致角度的不精确:一个有效角跨越 ~<math>0.0055°</math>。
</div>




'''Sin() and Cos() 代码''' (来自[[SourceCode:MathHelper|MathHelper]]):<syntaxhighlight lang="java">
'''Sin() Cos() 代码'''来自class MathHelper):<syntaxhighlight lang="java">
private static final float[] SIN_TABLE = new float[65536];
private static final float[] SIN_TABLE = new float[65536];




public static float sin(float value) //in radians
public static float sin(float value) //以弧度为单位
{
{
return SIN_TABLE[(int)(value * 10430.378F) & 65535];
return SIN_TABLE[(int)(value * 10430.378F) & 65535];
}
}


public static float cos(float value) //in radians
public static float cos(float value) //以弧度为单位
{
{
return SIN_TABLE[(int)(value * 10430.378F + 16384.0F) & 65535];
return SIN_TABLE[(int)(value * 10430.378F + 16384.0F) & 65535];
Line 43: Line 46:
}
}
}
}
</syntaxhighlight>'''Note:''' ''<code>& 65535</code>''给出除以 65536 的(正)余数(<math>2^{16}</math>)
</syntaxhighlight>'''注意:''' ''<code>& 65535</code>''给出除以 65536(<math>2^{16}</math>)的(正)余数


为了将玩家的偏航转换为弧度(当调用 sin 和 cos 时),游戏会使用这两个公式:<syntaxhighlight lang="java">
<div lang="en" dir="ltr" class="mw-content-ltr">
//通用公式
To convert the player's yaw into radians (when calling sin and cos), the game uses two formulas:<syntaxhighlight lang="java">
//formula used in general
f = this.rotationYaw * (float)Math.PI / 180.0F
f = this.rotationYaw * (float)Math.PI / 180.0F
</div>


////添加sprintjump boost时使用的公式
<div lang="en" dir="ltr" class="mw-content-ltr">
//formula used when adding sprintjump boost
f = this.rotationYaw * 0.017453292F
f = this.rotationYaw * 0.017453292F
</syntaxhighlight>
</syntaxhighlight>
它们的目的是一样的,但对于较大的值,结果可能不同。
Both have the same intent, but for large values the result may be different.
</div>


在这种情况下,疾跑跳跃会使玩家稍微向一侧移动,这对于创造无转向跳法可能很有用。
<div lang="en" dir="ltr" class="mw-content-ltr">
In that case, sprintjumping moves the player slightly to the side, which may be useful for no-turn strats.
</div>


<span id="Half_Angles"></span>
== 半角 ==


<code>(int)(value * 10430.378F)</code> 和 <code>(int)(value * 10430.378F + 16384.0F)</code> 应该相隔 16384 个单位(90°),但由于浮点不精确,某些值可能会进一步相差 1 个或多个单位,导致与预期计算出现轻微偏差。


[[File:Half angle visualized.png|thumb|582x582px|两个连续的角度(30237 和 30238)和中间的正半角。]]'''半角'''就是这样的值,可以在连续角的“中间”找到(因此得名)。
<div lang="en" dir="ltr" class="mw-content-ltr">
== Half Angles ==
</div>


半角的存在完全是由于括号内的“+ 16384”。
<div lang="en" dir="ltr" class="mw-content-ltr">
<code>(int)(value * 10430.378F)</code> and <code>(int)(value * 10430.378F + 16384.0F)</code> should be 16384 units apart (90°), but because of floating point imprecision, some values could end up 1 or more units further, causing a slight shift from the intended calculation.
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
[[File:Half angle visualized.png|thumb|582x582px|Two consecutive angles (30237 and 30238) and a positive half angle in between.]]'''Half angles''' are such values, and can be found "between" consecutive angles (hence the name).
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
The existence of half angles is entirely due to the fact the term "+ 16384" is inside the parentheses.
</div>


半角在工具辅助跑酷之外没有太大用处:它们对跳跃距离的影响很小,并且它们几乎无法用于原速下的鼠标移动。
<div lang="en" dir="ltr" class="mw-content-ltr">
Half angles don't have much use outside of Tool-Assisted Parkour: their effect on jump distance is small, and they are hardly usable with real-time mouse movement.
</div>






每个半角都有一个相关的'''乘数''',代表其效益。
<div lang="en" dir="ltr" class="mw-content-ltr">
Each half-angle has an associated '''Multiplier''' that represents its effectiveness.
</div>


它对应于从 cos(f) 和 sin(f) 获得的单位向量的范数。
<div lang="en" dir="ltr" class="mw-content-ltr">
It corresponds to the norm of the unit vector obtained from cos(f) and sin(f).
</div>


从数学上讲,它应该始终等于 1,但在这种情况下并不成立。
<div lang="en" dir="ltr" class="mw-content-ltr">
Mathematically, it should always be equal to 1, but that doesn't hold true in this context.
</div>


* “增益”半角的范数大于 1:它们会提高移动速度。
<div lang="en" dir="ltr" class="mw-content-ltr">
* “减益”半角的范数小于 1:它们会降低移动速度。
* "Increasing" half angles have a norm greater than 1: they increase movement speed.
* "Decreasing" half angles have a norm lesser than 1: they decrease movement speed.
</div>




Line 108: Line 86:




<div lang="en" dir="ltr" class="mw-content-ltr">
<math display="inline">\left \|\vec{v}\right \|=\sqrt{\cos(f)^{2}+\sin(f)^{2}}</math>
<math display="inline">\left \|\vec{v}\right \|=\sqrt{\cos(f)^{2}+\sin(f)^{2}}</math>
</div>






当与给定的跳跃距离相乘时,它给出其所对应的半角增益后的跳跃距离上限。
<div lang="en" dir="ltr" class="mw-content-ltr">
When multiplied with a given jump distance, it gives an upper bound for the improved jump distance with its corresponding half-angle.
</div>








[[Special:MyLanguage/Positive Half Angles|有益的半角列表]]
<div lang="en" dir="ltr" class="mw-content-ltr">
[[Special:MyLanguage/Positive Half Angles|List of useful Half Angles]]
</div>








<span id="Large_Half_Angles"></span>
<div lang="en" dir="ltr" class="mw-content-ltr">
== Large Half Angles ==
== 大半角 ==
</div>


2021 年 7 月 27 日,kemytz 发现,在使用 Optifine 的快速运算(一种将有效角数量减少到4096个的功能)时,[https://youtu.be/eMDajBi_QW0 某些偏航角可以提供更高的速度]。实际上,这并非快速运算所特有的,而且很快就发现了原版的“大半角”。
<div lang="en" dir="ltr" class="mw-content-ltr">
On July 27th 2021, kemytz discovered that [https://youtu.be/eMDajBi_QW0 certain yaws grant more speed] when using Optifine Fast Math (a feature which reduces the number of significant angles down to 4096). In fact, this is not specific to fast math, and vanilla "large half angles" were discovered soon after.
</div>


由于在该范围内可以使用的精度浮点数较少,因此大半角更有效:角度最多可以移动 64 个单位,而不是移动一个单位。
<div lang="en" dir="ltr" class="mw-content-ltr">
Large half angles are more effective due to the low amount of precision floats can work with at that range: instead of being shifted by a single unit, angles can be shifted by up to 64 units.
</div>


例如,偏航角为 5898195° 时的乘数为 1.003,这与小半角(135.0055° 的乘数为 1.00005)相比是巨大的。这个半角是目前最有效的存在,并使 [https://youtu.be/bQfl2Lleafw 2.125bm 4+0.5] 之类的跳跃成为可能。
<div lang="en" dir="ltr" class="mw-content-ltr">
For example, the yaw 5898195° gives a multiplier of 1.003, which is huge compared to small half angles (135.0055° gives a multiplier of 1.00005). This half angle is the most effective that exists, and makes jumps such as [https://youtu.be/bQfl2Lleafw 2.125bm 4+0.5] possible.
</div>


要达到如此高的数值可能需要使用宏或模组,因为手动旋转会耗费大量时间。
<div lang="en" dir="ltr" class="mw-content-ltr">
Reaching such high values may require using macros or mods, as turning manually would take too long.
</div>




通过快速运算,半角被进一步放大,玩家可以在偏航角小于 <math>360 \times 2^{19}</math> 运动,而在原版中只能在 <math>360 \times 2^{15}</math> 内运动。
<div lang="en" dir="ltr" class="mw-content-ltr">
With Fast Math, half angles are further amplified and the player is able to move while their yaw is less than <math>360 \times 2^{19}</math>, compared to <math>360 \times 2^{15}</math> in vanilla.
</div>


例如,偏航角 121000000° 的乘数是 1.09,这是如此荒谬,它使[https://youtu.be/Juz9bDZa5rc 平地连跳五远成为可能]。这个机制不应被视为官方机制,因为它依赖于 Mod,并且在服务器上使用这个漏洞可能是未经许可的(即使是 Optifine)。
<div lang="en" dir="ltr" class="mw-content-ltr">
For example, the yaw 121000000° gives a multiplier of 1.09, which is so ludicrous it makes [https://youtu.be/Juz9bDZa5rc flat momentum 5b possible]. This mechanic should not be considered official as it relies on a mod, and using this exploit is likely not authorized on servers (even if Optifine is).
</div>


新版本的 Optifine 改变了快速运算的效果,消除了大量快速运算半角(自 2019 年 12 月发布的 U L5 版本以来)。
<div lang="en" dir="ltr" class="mw-content-ltr">
New versions of Optifine changed the effect of fast math, which eliminated a lot of FM half angles (since version U L5, released in december 2019).
</div>






<span id="Characterization"></span>
<div lang="en" dir="ltr" class="mw-content-ltr">
== Characterization ==
== 特征 ==
</div>


减益半角在 -90° 和 0° 之间很常见,因为负浮点数向上截断,而正浮点数向下截断。
<div lang="en" dir="ltr" class="mw-content-ltr">
Decreasing half angles are abundant between -90° and 0°, because negative floats are truncated up while positive floats are truncated down.
</div>


在 0° 和 90° 之间几乎不存在减益半角。
<div lang="en" dir="ltr" class="mw-content-ltr">
Decreasing half angles exist rarely between 0° and 90°.
</div>


增益半角很少出现在 90° 和 180° 之间。
<div lang="en" dir="ltr" class="mw-content-ltr">
Increasing half angles exist rarely between 90° and 180°.
</div>


大半角的形式为 <math>360 \times 2^n - \theta</math>,其中 <math>\theta \in [0,90]</math> 且 <math>n \in \{0, ... ,14\}</math>。它们都为增益直到 <math>n \geq 8</math>,此时它们既可能是增益又可能是减益。
<div lang="en" dir="ltr" class="mw-content-ltr">
Large half angles are of the form <math>360 \times 2^n - \theta</math>, with <math>\theta \in [0,90]</math> and <math>n \in \{0, ... ,14\}</math>. They are all increasing until <math>n \geq 8</math>, at which point they may either be increasing or decreasing.
</div>

Latest revision as of 09:06, 26 December 2023

Other languages:

本文是鼠标运动的延续,着重介绍三角函数在 Minecraft 中的工作原理。


玩家的偏航角是一个浮点数,用于跟踪玩家的水平旋转(以度为单位)。它是无限的

玩家的朝向是将偏航角限制在 [-180°, 180°],如 F3 所示。

有效角,或者简单地说,角度是一个整数(从 )。



有效角

Minecraft 的三角函数依赖于有效角,即玩家的偏航角必须转换为一个具体角度。

这种转换导致角度的不精确:一个有效角跨越 ~Failed to parse (syntax error): {\displaystyle 0.0055°}


Sin() 与 Cos() 源代码(来自class MathHelper):

private static final float[] SIN_TABLE = new float[65536];


public static float sin(float value) //以弧度为单位
{
    return SIN_TABLE[(int)(value * 10430.378F) & 65535];
}

public static float cos(float value) //以弧度为单位
{
    return SIN_TABLE[(int)(value * 10430.378F + 16384.0F) & 65535];
}


static
{
    for (int i = 0; i < 65536; ++i)
    {
        SIN_TABLE[i] = (float)Math.sin((double)i * Math.PI * 2.0D / 65536.0D);
    }
}

注意: & 65535给出除以 65536()的(正)余数 为了将玩家的偏航转换为弧度(当调用 sin 和 cos 时),游戏会使用这两个公式:

//通用公式
f = this.rotationYaw * (float)Math.PI / 180.0F

////添加sprintjump boost时使用的公式
f = this.rotationYaw * 0.017453292F

它们的目的是一样的,但对于较大的值,结果可能不同。

在这种情况下,疾跑跳跃会使玩家稍微向一侧移动,这对于创造无转向跳法可能很有用。

半角

(int)(value * 10430.378F)(int)(value * 10430.378F + 16384.0F) 应该相隔 16384 个单位(90°),但由于浮点不精确,某些值可能会进一步相差 1 个或多个单位,导致与预期计算出现轻微偏差。

两个连续的角度(30237 和 30238)和中间的正半角。

半角就是这样的值,可以在连续角的“中间”找到(因此得名)。

半角的存在完全是由于括号内的“+ 16384”。


半角在工具辅助跑酷之外没有太大用处:它们对跳跃距离的影响很小,并且它们几乎无法用于原速下的鼠标移动。


每个半角都有一个相关的乘数,代表其效益。

它对应于从 cos(f) 和 sin(f) 获得的单位向量的范数。

从数学上讲,它应该始终等于 1,但在这种情况下并不成立。

  • “增益”半角的范数大于 1:它们会提高移动速度。
  • “减益”半角的范数小于 1:它们会降低移动速度。




当与给定的跳跃距离相乘时,它给出其所对应的半角增益后的跳跃距离上限。



有益的半角列表



大半角

2021 年 7 月 27 日,kemytz 发现,在使用 Optifine 的快速运算(一种将有效角数量减少到4096个的功能)时,某些偏航角可以提供更高的速度。实际上,这并非快速运算所特有的,而且很快就发现了原版的“大半角”。

由于在该范围内可以使用的精度浮点数较少,因此大半角更有效:角度最多可以移动 64 个单位,而不是移动一个单位。

例如,偏航角为 5898195° 时的乘数为 1.003,这与小半角(135.0055° 的乘数为 1.00005)相比是巨大的。这个半角是目前最有效的存在,并使 2.125bm 4+0.5 之类的跳跃成为可能。

要达到如此高的数值可能需要使用宏或模组,因为手动旋转会耗费大量时间。


通过快速运算,半角被进一步放大,玩家可以在偏航角小于 运动,而在原版中只能在 内运动。

例如,偏航角 121000000° 的乘数是 1.09,这是如此荒谬,它使平地连跳五远成为可能。这个机制不应被视为官方机制,因为它依赖于 Mod,并且在服务器上使用这个漏洞可能是未经许可的(即使是 Optifine)。

新版本的 Optifine 改变了快速运算的效果,消除了大量快速运算半角(自 2019 年 12 月发布的 U L5 版本以来)。


特征

减益半角在 -90° 和 0° 之间很常见,因为负浮点数向上截断,而正浮点数向下截断。

在 0° 和 90° 之间几乎不存在减益半角。

增益半角很少出现在 90° 和 180° 之间。

大半角的形式为 ,其中 。它们都为增益直到 ,此时它们既可能是增益又可能是减益。