题意
给出 3 3 3个点的坐标,求出这个坐标构成的平行四边形的面积。
思路
利用这
3
3
3个点组成的平行四边形的面积就为这
3
3
3个点的叉积的绝对值。
公式:点
p
1
(
x
1
,
y
1
)
p1(x1,y1)
p1(x1,y1)和点
p
2
(
x
2
,
y
2
)
p2(x2,y2)
p2(x2,y2)相对原点
(
0
,
0
)
(0,0)
(0,0)的叉积为
m
=
(
x
1
∗
y
2
)
−
(
x
2
∗
y
1
)
m=(x1*y2)-(x2*y1)
m=(x1∗y2)−(x2∗y1)
代码
#include<cstdio>
int t;
double CP(double x, double y, double a, double b, double c, double d) {
return (a - x) * (d - y) - (c - x) * (b - y);//相对于(x,y)
}
int main() {
scanf("%d", &t);
double x[4], y[4];
for (int i = 1; i <= t; i++) {
scanf("%lf %lf %lf %lf %lf %lf", &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]);
double ans = CP(x[1], y[1], x[2], y[2], x[3], y[3]);
if (ans < 0) ans *= -1;
if (!ans) printf("Error\n");
else printf("%.1lf\n", ans);
}
}