Ruas Garis

Asslamualaikum, . .
Kali ini saya akan membagikan tentang cara mencari ruas garis pada pemrograman java, . .
Silahkan dicoba, . .

import java.util.Scanner;

public class LineSegment {
   
    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("(" + x2 + ", " + y2 + ") is not on the line segment" +
                    " from (" + x0 + ", " + y0 + ") to (" + x1 + ", " + y1 + ")");
        else
            System.out.println("(" + x2 + ", " + y2 + ") is on the line segment" +
                    " from (" + x0 + ", " + y0 + ") to (" + x1 + ", " + y1 + ")");
    }
       
}


Semoga bermanfaat, . .

Subscribe to receive free email updates:

0 Response to "Ruas Garis"

Post a Comment