Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Last active May 10, 2026 11:46
Show Gist options
  • Select an option

  • Save thinkphp/62885f1817639cee2dd3458e257a7997 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/62885f1817639cee2dd3458e257a7997 to your computer and use it in GitHub Desktop.
Puncte coliniare. problema
/*
P1 , P2, P3
Panta P1P2 == Panta P2P3 sunt coliniare
m = y2 - y1 / x2 - x1
Panta a doua puncte iti spune cat de inclinata este dreapta care trece prin ele, adica cat de mult creste sau scade valoarea lui y atunci cand x creste
| x1 y1 1 |
| x2 y2 1 | = 0 determinatul este nul atunci sunt coliniare
| x3 y3 1 |
===
||
\/
x1(y2-y3) - y1(x2-x3) + (x2*y3 - x3*y2)
*/
import java.util.Scanner;
public class ColiniarePoints {
static class Punct {
double x, //abscina
y; //ordonata
//constructorul clasei Punct
Punct(double x, double y) {
this.x = x;
this.y = y;
}
}
//static boolean suntColiniare(Punct p1, Punct p2, Punct p3) {
//panta P1P2 m1=(y2-y1/x2-x1)
//panta P2P3 m2=(y3-y2)/(x3-x2)
//daca cele doua pante m1 == m2 atunci punctele sunt coliniare
//altfel nu sunt coliniare
//}
static boolean suntColiniare(Punct p1, Punct p2, Punct p3) {
double determinant = p1.x * (p2.y - p3.y)
- p1.y * (p2.x - p3.x)
+ p2.x * p3.y - p3.x * p2.y;
return Math.abs(determinant) < 1e-9; //toleranta opsilon
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Punct[] puncte = new Punct[ 3 ];
System.out.println("Introduceti coordonatele punctelor:");
for(int i = 0; i < 3; ++i) {
System.out.printf("Punctul %d:%n", i + 1);
System.out.println("Abscisa x = ");
double x = scanner.nextDouble();
System.out.println("Ordonata y = ");
double y = scanner.nextDouble();
//creat puncte[0], puncte[1], puncte[2]
puncte[i] = new Punct(x,y);
}
boolean resultatDeterminant = suntColiniare(puncte[0], puncte[1], puncte[2]);
//boolean resultatPanta = suntColiniarePanta(puncte[0], puncte[1], puncte[2]);
System.out.println("Metoda determinantului :" + (resultatDeterminant ? "coliniare":"nu sunt coliniare"));
}
}
/*
| x
| x
| x
|
-----------------
|
|
|
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment