import java.util.Scanner;
public class Main {
static class Point {
double x, y;
Point(double a, double b) {
x = a;
y = b;
}
}
static class Triangle {
Point a, b, c;
Triangle(Point a, Point b, Point c) {
this.a = a;
this.b = b;
this.c = c;
}
}
static double distance(Point a,Point b) {
double d=Math.sqrt(Math.pow(a.x-b.x, 2)+Math.pow(a.y-b.y, 2));
return d;
}
static double getArea(Triangle T) {
// TODO: 计算三角形T的面积
double ba=distance(T.a, T.b);
double bc=distance(T.b, T.c);
double ac=distance(T.a, T.c);
double cosB=(ba*ba+bc*bc-ac*ac)/(2*ba*bc);
double sinB=Math.sqrt(1-cosB*cosB);
double s=bc*ba*sinB;
return s/2;//一定要除二
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int x, y;
x = scanner.nextInt();
y = scanner.nextInt();
Point a = new Point(x, y);
x = scanner.nextInt();
y = scanner.nextInt();
Point b = new Point(x, y);
x = scanner.nextInt();
y = scanner.nextInt();
Point c = new Point(x, y);
Triangle T = new Triangle(a, b, c);
System.out.printf("%.2f%n", getArea(T));
scanner.close();
}
}
本题一定要注意三角形面积得除二



京公网安备 11010502036488号