Metroids/Game/src/MathShit.java

30 lines
868 B
Java

public class MathShit
{
/**
* Calculates the x-component of a vector, rotated around 0|0 by angle
* @param angle angle to rotate, in radians
* @param x old x-component of the vector or point
* @param y old y-component of the vector or point
* @return the new x component
*/
public static float rotateX(double angle, float x, float y)
{
double beta = (2*Math.PI)-angle;
return (float) (Math.cos(beta)*x-Math.sin(beta)*y);
}
/**
* Calculates the y-component of a vector, rotated around 0|0 by angle
* @param angle angle to rotate, in radians
* @param x old x-component of the vector or point
* @param y old y-component of the vector or point
* @return the new y-component
*/
public static float rotateY(double angle, float x, float y)
{
double beta = (2*Math.PI)-angle;
return (float) (Math.sin(beta)*x+Math.cos(beta)*y);
}
}