1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| double timeToSimulate = 8f;
double timeStep = 0.0001f; // seconds
double gravity = 9.81f; // m/s/s
double muzzleVelocity = 950; // m/s
double zeroingRange = 254;// m
double targetRange = 500; // m
double dragForce = 0.00095f;
double mildots;
List<Vecteur2> positionList = new LinkedList<Vecteur2>();
List<Vecteur2> rotatedPositionList = new LinkedList<Vecteur2>();
public void DoMath() {
//Initial simulationic void DoMath()
Vecteur2 velocityVector = new Vecteur2(muzzleVelocity, 0);
Vecteur2 positionVector = new Vecteur2(0, 0);
positionList.add(positionVector);
for (double t = 0; t <= timeToSimulate; t += timeStep) {
double frictionAcceleration = dragForce * velocityVector.LengthSquared();
//compute total acceleration on the bullet
Vecteur2 accelerationVector = Vecteur2.Normalize(velocityVector).negatif().multiplie(frictionAcceleration).plus(new Vecteur2(0, -gravity));
//d = 1/2*a*t^2 + vi*t + d0;
positionVector = positionVector.plus(velocityVector.multiplie(timeStep).plus(accelerationVector.multiplie(1/2).multiplie(timeStep).multiplie(timeStep)));
positionList.add(positionVector);
//vf = vi + at
velocityVector = velocityVector.plus(accelerationVector.multiplie(timeStep));
}
//Solve for zeroing position
Vecteur2 zeroingPosition = new Vecteur2(0, 0);
double smallestDistance = 100000;
for (int i = 0; i < positionList.size(); i++) { //Erreure possible: size() ici remplace Count en c#
Vecteur2 thisPos = positionList[i]; // Error:(44) error: array required, but List<Vecteur2> found
double distanceFromOrigin = thisPos != Vecteur2.Zero() ? thisPos.Length() : 0f;
double thisDistance = Math.abs(distanceFromOrigin - zeroingRange);
if (thisDistance < smallestDistance) {
zeroingPosition = thisPos;
smallestDistance = thisDistance;
}
}
//Get elevation angle for zeroing
double zeroingElevationAngle = zeroingPosition != Vecteur2.Zero() ? Math.atan(zeroingPosition.y / -zeroingPosition.x) : 0.0;
double cos = (double) Math.cos(zeroingElevationAngle);
double sin = (double) Math.sin(zeroingElevationAngle);
//Create rotation matrix (matricies are transposed from math conventions)
Matrix3x2 rotationMatrix = new Matrix3x2();
rotationMatrix.m11 = cos;
rotationMatrix.m12 = sin;
rotationMatrix.m21 = -sin;
rotationMatrix.m22 = cos;
//Rotate all of our values
for (int i = 0; i < positionList.size(); i++) {
rotatedPositionList.Add(Vecteur2.TransformNormal(positionList[i], rotationMatrix)); // Error: error: array required, but List<Vecteur2> found
}
//Solve for desired range
Vecteur2 targetPos = new Vecteur2(0, 0);
smallestDistance = 100000;
for (int i = 0; i < rotatedPositionList.size(); i++) {
Vecteur2 thisPos = rotatedPositionList[i]; // Error: error: array required, but List<Vecteur2> found
double thisDistance = Math.abs(thisPos.x - targetRange);
if (thisDistance < smallestDistance) {
targetPos = thisPos;
smallestDistance = thisDistance;
}
}
mildots = (double) Math.atan(-targetPos.y / targetPos.x) * 1000f;
String direction = mildots > 0 ? "above" : "below";
button1.setText("Aim {Math.Abs(mildots):N2} mildots {direction} target");
}
} |
Partager