Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Quellcode |
|
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 |
package kanone; import static java.lang.Math.cos; import static java.lang.Math.sin; import java.util.Scanner; public class Kanone { public static void main(String[] args) { double g=9.81; int entfernung; int alpha; double alpha0; int v0; double x; double y; int t; String nochmal; Scanner sc = new Scanner(System.in); do{ System.out.println("Kanonenschuss"); System.out.println("============="); System.out.println(); System.out.println("Versuchen sie das Ziel (+50 und -50 Meter) zu treffen indem sie die Anfangsgeschwindigkeit und die Winkel der Kugel eingeben."); entfernung = ZufZa(9950) + 50; System.out.println(); System.out.println("Versuche das Ziel in " + entfernung + " Metern Entfernung zu treffen!"); System.out.println(); System.out.print("Anfangsgeschwindigkeit(in m/s): "); v0 = sc.nextInt(); System.out.print("Winkel (Alpha in Grad): "); alpha = sc.nextInt(); System.out.println(); t=1; x=v0*cos(alpha)*t; y=v0*sin(alpha)*t-(g*t*t/2); System.out.println("x: "+x); System.out.println("y: "+y); System.out.print("Wollen sie nochmal? (J) "); nochmal=sc.next(); System.out.println(); }while(nochmal.equalsIgnoreCase("j")); } public static int ZufZa(int limit) { return (int) (Math.random() * (double) limit); } } |
Zitat
sin
public static double sin(double a)
Returns the trigonometric sine of an angle. Special cases:
If the argument is NaN or an infinity, then the result is NaN.
If the argument is zero, then the result is a zero with the same sign as the argument.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
Parameters:
a - an angle, in radians.
Returns:
the sine of the argument.
Community-Fossil
Er meint die Java Doku. Umrechnung:
alphaInRad = alpha*PI/180
Erstmal in Radiant umrechnen, aber auch dann kommt nichts richtiges bei raus (hier in Grad, ich gehe davon aus das sin(90) also 1 zurück gibt):
1×sin(90)×1−(9,81×1×1÷2) = -3,905
Die Formel scheint also nicht zu stimmen. Guck dir noch mal die Wurfparabel an.
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Checkmateing« (31.01.2015, 18:53)
Zitat
Ich muss mir ja die wurfweite berechnen. Und ich berechne x solange für jede einzelne sekunde, bis y kleinergleich 0 ist.
Werbeanzeige