Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is what I have currently for aiming my turret, if anyone can help it shouldn't be hard to know how.
- import java.util.*;
- /**
- * Write a description of class MathTesting here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class MathTesting
- {
- //
- static Random rand2 = new Random();
- public static void main(String[] args)
- {
- for(int RF = 0; RF < rand2.nextInt(1000); RF++)
- {
- System.out.println("Round: " + RF);
- double TurretX = TrueRandDouble(10), TurretY = TrueRandDouble(10), FoeX = TrueRandDouble(10), FoeY = TrueRandDouble(1000);
- double DistanceX = FoeX - TurretX;
- double DistanceY = FoeY - TurretY;
- double RadAngle = Math.atan2(DistanceY, DistanceX);
- double PolarAngle = Math.toDegrees(Math.atan2(DistanceY, DistanceX));
- double RealAngle = PolarAngle;
- System.out.println("TX = " + TurretX + " TY = " + TurretY + " FX = " + FoeX + " FY = " + FoeY);
- System.out.println("Distance X = " + DistanceX + " Distance Y = " + DistanceY);
- System.out.println("Real Distance = " + Distance(TurretX,TurretY,FoeX,FoeY));
- System.out.println("Math atan = " + Math.atan2(DistanceY, DistanceX));
- System.out.println("PolarAngle = " + Math.toDegrees(Math.atan2(DistanceY, DistanceX)));
- if(PolarAngle < 0)
- {
- RealAngle = PolarAngle + 360;
- }
- if(PolarAngle > 360)
- {
- RealAngle = PolarAngle - 360;
- }
- if(PolarAngle < 360 && PolarAngle > 0)
- {
- RealAngle = PolarAngle;
- }
- System.out.println("RealAngle = " + RealAngle);
- double FaceAngle = (double)rand2.nextInt(360);
- if(FaceAngle != RealAngle)
- {
- FaceAngle = RealAngle;
- }
- System.out.println("FaceAngle = " + FaceAngle);
- System.out.println();
- }
- }
- public static double Distance(double X1, double Y1, double X2, double Y2)
- {
- double D = Math.sqrt( Math.abs( (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1) ) );
- return D;
- }
- public static int TrueRandDouble(int RandCap)
- {
- int RandN = rand2.nextInt(RandCap);
- int TRD = 0;
- int NorP = rand2.nextInt(2);
- switch(NorP)
- {
- case 0:
- TRD = (RandN * -1);
- break;
- case 1:
- TRD = (RandN * 1);
- break;
- }
- return TRD;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement