Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static double angle2d(double cX, double cZ, double pX, double pZ) {
- if (cX == cZ) {
- if (pZ > cZ) {
- return 180;
- }
- else if (pZ < cZ) {
- return 0;
- }
- else {
- throw new RuntimeException("Points were equal");
- }
- }
- else if (pZ == cZ) {
- if (pX > cX) {
- return 90;
- }
- else if (pX < cX) {
- return 270;
- }
- else {
- throw new RuntimeException("Points were equal");
- }
- }
- else {
- double theta = Math.atan2(pX - cX, -(pZ - cZ));
- if (theta < 0.0) {
- theta += 6.2831853071795865d;
- }
- return 57.2957795130823209d * theta;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment