UVa 12165 - Triangle Hazard

链接

传送门

题意

如图,给出\(P\)\(Q\)\(R\)三个点的坐标和\(m1:m2\)\(m3:m4\)\(m5:m6\)的值。求\(A\)\(B\)\(C\)的坐标。

思路

由梅涅劳斯定理可得:

\[\frac{AR}{RP} \cdot \frac{PQ}{QB} \cdot \frac{BD}{DC} = 1\]

即:

\[\frac{AR}{RP} \cdot \frac{PQ}{QB} = \frac{m_5}{m_6}\]

\[k_1 = \frac{m_5}{m_6}, \space k_2 = \frac{m_1}{m_2}, \space k_3 = \frac{m_3}{m_4}\]

化简得:

\[\frac{AR}{RP} = k_1 \left( \frac{BP}{PQ} + 1 \right)\]

同理可得,

\[\frac{BP}{PQ} = k_2 \left( \frac{CQ}{QR} + 1 \right), \space \frac{CQ}{QR} = k_3 \left( \frac{AR}{RP} + 1 \right)\]

解得:

\[\frac{AR}{RP} = \frac{k_1k_2k_3 + k_1k_2 + k_1}{1 - k_1k_2k_3}\]

\[\frac{BP}{PQ} = \frac{k_1k_2k_3 + k_2k_3 + k_2}{1 - k_1k_2k_3}\]

\[\frac{CQ}{QR} = \frac{k_1k_2k_3 + k_3k_1 + k_3}{1 - k_1k_2k_3}\]

然后利用向量乘法很容易解决了。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

struct Point {
double x, y;
Point() {}
Point(double x, double y): x(x), y(y) {}
} P, Q, R, A, B, C;

typedef Point Vector;

Vector operator + (const Point& a, const Point& b) {
return Point(a.x + b.x, a.y + b.y);
}

Vector operator - (const Point& a, const Point& b) {
return Point(a.x - b.x, a.y - b.y);
}

Vector operator * (const Point& a, const double& k) {
return Point(a.x * k, a.y * k);
}

int main() {
int t;
scanf("%d", &t);
while (t--) {
double m1, m2, m3, m4, m5, m6;
scanf("%lf%lf%lf%lf%lf%lf", &P.x, &P.y, &Q.x, &Q.y, &R.x, &R.y);
scanf("%lf%lf%lf%lf%lf%lf", &m1, &m2, &m3, &m4, &m5, &m6);
double k1 = m5 / m6, k2 = m1 / m2, k3 = m3 / m4, k = k1 * k2 * k3;
A = (R - P) * ((k + k1 * k2 + k1) / (1 - k)) + R;
B = (P - Q) * ((k + k2 * k3 + k2) / (1 - k)) + P;
C = (Q - R) * ((k + k3 * k1 + k3) / (1 - k)) + Q;
printf("%.8f %.8f %.8f %.8f %.8f %.8f\n", A.x, A.y, B.x, B.y, C.x, C.y);
}
return 0;
}