O
OhMannoMann
Gast
Hey,
ich hab folgendes Programm geschrieben, welches den abstand eines punktes r zu einer geraden pq ausrechnen soll.
Sollte soweit eigentlich stimmen, allerdins bekomm ich den Abstand in einer Zeile ausgespuckt, und darunter immer NaN.
imacrakt2 Sam$ java Dist 1 11 1 4 6 9
5.0
NaN
Woher kommt die zweite ausgabe und wie krieg ich die weg?
Schon mal Dangge.....Sam
ich hab folgendes Programm geschrieben, welches den abstand eines punktes r zu einer geraden pq ausrechnen soll.
Code:
//Samantha Vordermeier GOB1B
public class Dist
{
public static void main(String... args)
{
double xp = Double.parseDouble(args[0]);
double yp = Double.parseDouble(args[1]);
double xq = Double.parseDouble(args[2]);
double yq = Double.parseDouble(args[3]);
double xr = Double.parseDouble(args[4]);
double yr = Double.parseDouble(args[5]);
double m;
double t1;
double t2;
double xl;
double yl;
double Dist;
if (xq - xp == 0)
{
Dist = Math.abs(xp - xr);
System.out.println(Dist);
}
m = (yq - yp) / (xq - xp);
if(m == 0)
{
Dist = yr - yp;
System.out.println(Dist);
}
else if(m != 0)
{
t1 = yp - ((yq-yp) / (xq-xp)) * xp;
m = (yq - yp) / (xq -xp);
xl = (yr + xr/m - t1) / (m + 1/m);
yl = m * xl + t1;
Dist = Math.sqrt((xl-xr) * (xl-xr) + (yl-yr) * (yl-yr));
System.out.println(Dist);
}
}
}
Sollte soweit eigentlich stimmen, allerdins bekomm ich den Abstand in einer Zeile ausgespuckt, und darunter immer NaN.
imacrakt2 Sam$ java Dist 1 11 1 4 6 9
5.0
NaN
Woher kommt die zweite ausgabe und wie krieg ich die weg?
Schon mal Dangge.....Sam