#P10410. Minimizing the Area of p-Proportional Triangle
Minimizing the Area of p-Proportional Triangle
Minimizing the Area of p-Proportional Triangle
Little R is struggling with a geometry problem. Given a triangle \(\triangle ABC\) with vertices \(A(x_1,y_1)\), \(B(x_2,y_2)\) and \(C(x_3,y_3)\) in the Cartesian plane, for a real number \(p\in(0,1)\), we place points on the sides:
- Point \(F\) is on \(AB\) such that \(\frac{|AF|}{|AB|}=p\) (i.e. \(F=A+p(B-A)\)).
- Point \(D\) is on \(BC\) such that \(\frac{|BD|}{|BC|}=p\) (i.e. \(D=B+p(C-B)\)).
- Point \(E\) is on \(CA\) such that \(\frac{|CE|}{|CA|}=p\) (i.e. \(E=C+p(A-C)\)).
The triangle \(\triangle DEF\) formed in this way is called the "p-proportional triangle" of \(\triangle ABC\). Its area, as a function of \(p\), can be computed using barycentric coordinates and turns out to be \[ S_{DEF} = \left((1-p)^3+p^3\right)\, S_{ABC}, \] where \(S_{ABC}\) is the area of \(\triangle ABC\), given by \[ S_{ABC}=\frac{1}{2}\left|x_1(y_2-y_3)+x_2(y_3-y_1)+x_3(y_1-y_2)\right|. \]
You are given an interval \([l, r]\) and you need to choose \(p\) (with \(p\in[l,r]\)) so that \(S_{DEF}\) is minimized. Note that the function \(f(p)=(1-p)^3+p^3\) is convex in \(p\) with the minimum attained at \(p=\frac{1}{2}\). Therefore, if \(\frac{1}{2}\in[l,r]\) then the optimal \(p\) is \(\frac{1}{2}\); otherwise, the optimum is at one of the endpoints.
Compute and output the minimal area of \(\triangle DEF\).
inputFormat
The input consists of a single line containing eight real numbers:
\(x_1\ y_1\ x_2\ y_2\ x_3\ y_3\ l\ r\)
It is guaranteed that \(\triangle ABC\) is non-degenerate and \(0 < l < r < 1\).
outputFormat
Output a single real number — the minimum area of the p-proportional triangle \(\triangle DEF\). Your answer will be accepted if its absolute or relative error does not exceed \(10^{-6}\).
sample
0 0 3 0 0 4 0.0 1.0
1.5