Hari ini saya akan membagikan tentang mencari titik pada pemrograman java. .
langsung saja dicoba, .
import java.util.Scanner;
public class PointPosition {
public static void main(String[] iriahus) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
System.out.print("Enter three points for p0, p1 and p2: ");
double x0 = s.nextDouble();
double y0 = s.nextDouble();
double x1 = s.nextDouble();
double y1 = s.nextDouble();
double x2 = s.nextDouble();
double y2 = s.nextDouble();
double p2 = (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0);
if (p2 > 0)
System.out.println("p2 is on the left side of the line");
else if (p2 < 0)
System.out.println("p2 is on the right side of the line");
else
System.out.println("p2 is on the same line");
}
}
Semoga bermanfaat. . .
0 Response to "Posisi Titik"
Post a Comment