Angles: Difference between revisions

From Minecraft Parkour Wiki
Content added Content deleted
No edit summary
(→‎Angles and Half Angles: added to trig explanation)
Line 16: Line 16:




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


public static float cos(float value)
public static float cos(float value) //in radians
{
{
return SIN_TABLE[(int)(value * 10430.378F + 16384.0F) & 65535];
return SIN_TABLE[(int)(value * 10430.378F + 16384.0F) & 65535];
Line 34: Line 34:
}
}
}
}
</syntaxhighlight>'''Note:''' ''<code>& 65535</code>'' is the same as ''<code>% 65536</code>'', which is the 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>)


<br />By analyzing the '''sin()''' and '''cos()''' function from the source code, we can notice that the yaw-to-angle conversion is not exactly the same for both functions.
<br />By analyzing the '''sin()''' and '''cos()''' functions above, we can notice that the yaw-to-angle conversion is incorrect for cos():
* Implemented version: <code>(int)(value * 10430.378F + 16384.0F)</code>
* "Correct" version: <code>((int)(value * 10430.378F) + 16384)</code>


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 closer or further (this wouldn't happen if the correct version had been implemented).
Because floats are rather imprecise for larger values, this means the same value could potentially be converted differently.




'''Half angles''' are such values, and can found between consecutive angles (hence the name).
'''Half angles''' are such values, and can found "between" consecutive angles (hence the name).


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 can hardly be reached with mouse movement.
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.


* Positive half-angles increase the Player's speed. They can be found (rarely) in the North-West quadrant (90° to 180°)
* Positive half-angles increase the Player's speed. They can be found (rarely) in the North-West quadrant (90° to 180°)

Revision as of 20:57, 26 February 2020

The Player's yaw (facing) is a float (from to )

An angle is an integer (from to )


Angles and Half Angles

Minecraft relies on angles for movement calculations, which means the Player's yaw has to be converted before being used.

This conversion induces some imprecision, as information is lost when casting a float to an int.

This also means two close (but different) facings can result in the same significant angle being used (a single angle spans across ~Failed to parse (syntax error): {\displaystyle 0.0055°} ).


Sin() and Cos() source code (from 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 ( )


By analyzing the sin() and cos() functions above, we can notice that the yaw-to-angle conversion is incorrect for cos():

  • Implemented version: (int)(value * 10430.378F + 16384.0F)
  • "Correct" version: ((int)(value * 10430.378F) + 16384)

Ideally, (int)(value * 10430.378F) and (int)(value * 10430.378F + 16384.0F) would be 16384 apart. But because of float imprecision, some values could be closer or further (this wouldn't happen if the correct version had been implemented).


Half angles are such values, and can found "between" consecutive angles (hence the name).

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.

  • Positive half-angles increase the Player's speed. They can be found (rarely) in the North-West quadrant (90° to 180°)
  • Negative half-angles decrease the Player's speed. They can be found (abundantly) in the South-East quadrant (-90° to 0°).

The best half-angle is 135.0055° (combined with 45° Strafe)

Two consecutive angles (30237 and 30238) and a positive half angle in between.

Note: Fast Math is an Optifine feature that reduces the number of angles to 4096 ( ). With Fast Math, half angles are fewer in number, but are up to 16x more effective. For example, it makes a no-sprint 3b jump possible with only flat momentum.