Angles: Difference between revisions

From Minecraft Parkour Wiki
Content added Content deleted
(added graph)
mNo edit summary
 
(26 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<languages/>
The Player's yaw (facing) is a '''float''' (from <math display="inline">-180.0</math> to <math display="inline">180.0</math>)
<translate>
<!--T:1-->
This article is a continuation of [[Special:MyLanguage/Mouse Movement|Mouse Movement]], with a focus on how trigonometry works in Minecraft.


An angle is an '''integer''' (from <math display="inline">0</math> to <math display="inline">2^{16}-1</math>)




<!--T:2-->
== Angles and Half Angles ==
The player's '''yaw''' is a [https://en.wikipedia.org/wiki/Floating-point_arithmetic float] that keeps track of the player's horizontal rotation (in degrees). It is '''unbounded'''.
Minecraft relies on angles for movement calculations, which means the Player's yaw has to be converted before being used.


<!--T:3-->
This conversion induces some imprecision, as information is lost when casting a '''float''' to an '''int'''.
The player's '''facing''' is the restriction of the yaw to [-180°, 180°], as shown in [[Special:MyLanguage/Debug Screen|F3]].


<!--T:4-->
This also means two close (but different) facings can result in the same significant angle being used (a single angle spans across ~<math>0.0055°</math>).
A '''significant angle''', or simply '''angle''' is an integer (from <math display="inline">0</math> to <math display="inline">2^{16}-1</math>).





'''Sin() and Cos() source code''' (from [[SourceCode:MathHelper|MathHelper]]):<syntaxhighlight lang="java">


== Significant Angles == <!--T:5-->

<!--T:6-->
Minecraft relies on significant angles for its trigonometry, which means the player's yaw has to be converted to an angle.

<!--T:7-->
This conversion induces imprecision: a significant angle spans across ~<math>0.0055^{\circ}</math>).


<!--T:8-->
'''Sin() and Cos() source code''' (from class MathHelper):<syntaxhighlight lang="java">
private static final float[] SIN_TABLE = new float[65536];
private static final float[] SIN_TABLE = new float[65536];




<!--T:9-->
public static float sin(float value) //in radians
public static float sin(float value) //in radians
{
{
Line 21: Line 39:
}
}


<!--T:10-->
public static float cos(float value) //in radians
public static float cos(float value) //in radians
{
{
Line 27: Line 46:




<!--T:11-->
static
static
{
{
Line 36: Line 56:
</syntaxhighlight>'''Note:''' ''<code>& 65535</code>'' gives the (positive) remainder of a division by 65536 ( <math>2^{16}</math>)
</syntaxhighlight>'''Note:''' ''<code>& 65535</code>'' gives the (positive) remainder of a division by 65536 ( <math>2^{16}</math>)


<!--T:12-->
<br />By analyzing the '''sin()''' and '''cos()''' functions above, we can notice that the yaw-to-angle conversion is incorrect for cos(), as 16384 is added before casting to an int.
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

<!--T:13-->
//formula used when adding sprintjump boost
f = this.rotationYaw * 0.017453292F
</syntaxhighlight>
Both have the same intent, but for large values the result may be different.

<!--T:14-->
In that case, sprintjumping moves the player slightly to the side, which may be useful for no-turn strats.

== Half Angles == <!--T:15-->

<!--T:16-->
<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.

<!--T:17-->
[[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).

<!--T:18-->
The existence of half angles is entirely due to the fact the term "+ 16384" is inside the parentheses.

<!--T:19-->
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.



<!--T:20-->
Each half-angle has an associated '''Multiplier''' that represents its effectiveness.

<!--T:21-->
It corresponds to the norm of the unit vector obtained from cos(f) and sin(f).

<!--T:22-->
Mathematically, it should always be equal to 1, but that doesn't hold true in this context.

<!--T:23-->
* "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.





<!--T:24-->
<math display="inline">\left \|\vec{v}\right \|=\sqrt{\cos(f)^{2}+\sin(f)^{2}}</math>



<!--T:25-->
When multiplied with a given jump distance, it gives an upper bound for the improved jump distance with its corresponding half-angle.




<!--T:26-->
[[Special:MyLanguage/Positive Half Angles|List of useful Half Angles]]




== Large Half Angles == <!--T:27-->

<!--T:28-->
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.

<!--T:29-->
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.

<!--T:30-->
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.

<!--T:31-->
Reaching such high values may require using macros or mods, as turning manually would take too long.


Ideally, <code>(int)(value * 10430.378F)</code> and <code>(int)(value * 10430.378F + 16384.0F)</code> would be 16384 apart. But because of float imprecision, some values could be further by 1.


<!--T:32-->
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.


<!--T:33-->
'''Half angles''' are such values, and can found "between" consecutive angles (hence the name). [[File:Half Angles Multiplier graph.png|thumb|Graph showing the relative effect of Half Angles. A multiplier above 1 indicates a positive half angle.]]Half angles don't have much use outside of Tool-Assisted Parkour: their effect on jump distance is negligible (±0.0001 for Tier 0), and they are hardly usable with just mouse movement.
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).


<!--T:34-->
* Positive half-angles increase the Player's speed. They can be found (rarely) in the North-West quadrant (90° to 180°)
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).
* Negative half-angles decrease the Player's speed. They can be found (abundantly) in the South-East quadrant (-90° to 0°), as well as in the South-West quadrant (0° to 90°) in rare amounts.




The best half-angle for cardinal directions is 135.0055° (combined with 45° Strafe)<br />


== Characterization == <!--T:35-->


<!--T:36-->
[[Positive Half Angles|List of all positive Half Angles]]
Decreasing half angles are abundant between -90° and 0°, because negative floats are truncated up while positive floats are truncated down.


<!--T:37-->
Decreasing half angles exist rarely between 0° and 90°.


<!--T:38-->
[[File:Half angle visualized.png|none|thumb|582x582px|Two consecutive angles (30237 and 30238) and a positive half angle in between.]]
Increasing half angles exist rarely between 90° and 180°.


<!--T:39-->
'''Note:''' Fast Math is an Optifine feature that reduces the number of angles to 4096 ( <math>2^{12}</math>). With Fast Math, half angles are fewer in number, but are up to 16x more effective. For example, it makes a [https://youtu.be/19CNqn5r95o no-sprint 3b] jump possible with only flat momentum.
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.
</translate>

Latest revision as of 22:51, 22 December 2023

Other languages:

This article is a continuation of Mouse Movement, with a focus on how trigonometry works in Minecraft.


The player's yaw is a float that keeps track of the player's horizontal rotation (in degrees). It is unbounded.

The player's facing is the restriction of the yaw to [-180°, 180°], as shown in F3.

A significant angle, or simply angle is an integer (from to ).



Significant Angles

Minecraft relies on significant angles for its trigonometry, which means the player's yaw has to be converted to an angle.

This conversion induces imprecision: a significant angle spans across ~).


Sin() and Cos() source code (from class MathHelper):

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


public static float sin(float value) //in radians
{
    return SIN_TABLE[(int)(value * 10430.378F) & 65535];
}

public static float cos(float value) //in radians
{
    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);
    }
}

Note: & 65535 gives the (positive) remainder of a division by 65536 ( ) To convert the player's yaw into radians (when calling sin and cos), the game uses two formulas:

//formula used in general
f = this.rotationYaw * (float)Math.PI / 180.0F

//formula used when adding sprintjump boost
f = this.rotationYaw * 0.017453292F

Both have the same intent, but for large values the result may be different.

In that case, sprintjumping moves the player slightly to the side, which may be useful for no-turn strats.

Half Angles

(int)(value * 10430.378F) and (int)(value * 10430.378F + 16384.0F) 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.

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).

The existence of half angles is entirely due to the fact the term "+ 16384" is inside the parentheses.


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.


Each half-angle has an associated Multiplier that represents its effectiveness.

It corresponds to the norm of the unit vector obtained from cos(f) and sin(f).

Mathematically, it should always be equal to 1, but that doesn't hold true in this context.

  • "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.




When multiplied with a given jump distance, it gives an upper bound for the improved jump distance with its corresponding half-angle.



List of useful Half Angles



Large Half Angles

On July 27th 2021, kemytz discovered that 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.

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.

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 2.125bm 4+0.5 possible.

Reaching such high values may require using macros or mods, as turning manually would take too long.


With Fast Math, half angles are further amplified and the player is able to move while their yaw is less than , compared to in vanilla.

For example, the yaw 121000000° gives a multiplier of 1.09, which is so ludicrous it makes 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).

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).


Characterization

Decreasing half angles are abundant between -90° and 0°, because negative floats are truncated up while positive floats are truncated down.

Decreasing half angles exist rarely between 0° and 90°.

Increasing half angles exist rarely between 90° and 180°.

Large half angles are of the form , with and . They are all increasing until , at which point they may either be increasing or decreasing.