implemented direction calculation candidate
parent
c23e74d43e
commit
2b2a1b878e
|
@ -21,26 +21,20 @@ public class ArtyMath {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates angle from east of the vector.
|
* Calculates angle from east of the vector.
|
||||||
|
* Uses Minecraft coordinate styling for angle measures
|
||||||
|
* e.g. pi/2 is south (+z) and 3pi/2 is north (-z)
|
||||||
* @param vector Vector to calculate angle from
|
* @param vector Vector to calculate angle from
|
||||||
* @return Angle from east in radians
|
* @return Angle from east in radians
|
||||||
*/
|
*/
|
||||||
public static double calculateDirection(Vector vector){
|
public static double calculateDirection(Vector vector){
|
||||||
vector.setY(0);
|
|
||||||
Vector eastVector = new Vector(1,0,0);
|
|
||||||
return eastVector.angle(vector);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double calculateDirectionDOTPRODUCT(Vector vector){
|
|
||||||
double x = vector.getX();
|
double x = vector.getX();
|
||||||
double z = vector.getZ();
|
double z = vector.getZ();
|
||||||
double directionMagnitude = Math.sqrt((x*x)+(z*z));
|
double directionMagnitude = Math.sqrt((x*x)+(z*z));
|
||||||
//dot product is always going to just be the x value
|
//dot product is always going to just be the x value
|
||||||
//since the z value for the east vector is 0.
|
//since the z value for the east vector is 0.
|
||||||
return Math.acos(x/directionMagnitude);
|
double angle = Math.acos(x/directionMagnitude);
|
||||||
}
|
if(z < 0) angle = 2*Math.PI - angle;
|
||||||
|
return angle;
|
||||||
public static double calculateDirectionBASICTRIG(Vector vector){
|
|
||||||
return Math.atan(vector.getZ()/vector.getX());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue