Linear Gradient

시간 제한1초메모리 제한2048 MB

요약
사다리꼴을 채우는 그라디언트 선분의 색이 왼쪽에서 오른쪽으로 선형 보간될 때, 빨강, 초록, 파랑 영역의 총 넓이를 구한다.
난이도

보통10점 중 7점

유형
기하, 수학, 구현, 이분 탐색
정답자
아직 제출이 없습니다

문제

There is a trapezoid with vertices (x_1,y_1)(x\_1, y\_1), (x_1,y_2)(x\_1, y\_2), (x_2,y_3)(x\_2, y\_3), (x_2,y_4)(x\_2, y\_4) in the Euclidean plane that is painted with a linear gradient (defined below).

Let a triple of real numbers (r,g,b)(r, g, b) represent a color of a point, and let us use this to define three colors:

  • red: r≥150r \geq 150, g≤75g \leq 75, b≤75b \leq 75;
  • green: g≥150g \geq 150, r≤75r \leq 75, b≤75b \leq 75;
  • blue: b≥150b \geq 150, r≤75r \leq 75, g≤75g \leq 75.

The trapezoid is colored using a set of lines which collectively cover the entire area of the trapezoid and produce a color gradient. The set is defined as follows:

  • Each line in the set is defined by a value of tt (t∈\[0,1]t \in \[0, 1]).
  • The endpoints of the line are (x_1,(1−t)y_1+ty_2)(x\_1, (1 - t) y\_1 + t y\_2) and (x_2,(1−t)y_3+ty_4)(x\_2, (1 - t) y\_3 + t y\_4).
  • The color of the left endpoint is (r_ℓ,g_ℓ,b_ℓr\_{\ell}, g\_{\ell}, b\_{\ell}), and the color of the right endpoint is (r_r,g_r,b_rr\_r, g\_r, b\_r).
  • The color of an inner point on the line is determined by linear interpolation (see Note for definition) between the left and right colors, based on the distance from the left endpoint to that point.

Calculate the total area of the red, blue, and green parts of the trapezoid.

입력

The first line contains integers x_1x\_1, y_1y\_1, y_2y\_2, r_ℓr\_{\ell}, g_ℓg\_{\ell}, b_ℓb\_{\ell}.

The second line contains integers x_2x\_2, y_3y\_3, y_4y\_4, r_rr\_r, g_rg\_r, b_rb\_r.

출력

Output three real numbers: the red area, the blue area, and the green area, respectively. The absolute or relative error should not exceed 10−910^{-9}.

제한

  • 0≤x_1<x_2≤100,0000 \leq x\_1 < x\_2 \leq 100\\,000;
  • 0≤y_1<y_2≤100,0000 \leq y\_1 < y\_2 \leq 100\\,000;
  • 0≤y_3<y_4≤100,0000 \leq y\_3 < y\_4 \leq 100\\,000;
  • 0≤r_ℓ,g_ℓ,b_ℓ,r_r,g_r,b_r≤2550 \leq r\_{\ell}, g\_{\ell}, b\_{\ell}, r\_r, g\_r, b\_r \leq 255.

힌트

Linear interpolation is a method of estimating values within an interval, based on known values at the endpoints. In the context of color interpolation, it means that the color components (r,g,b)(r, g, b) are calculated as a weighted average of the corresponding components of the left and right colors, with the weights determined by the relative distance of the point from the left endpoint and the right endpoint. This creates a smooth transition of colors along the line.

예제1

  1. 예제 1

    입력
    0 0 50 255 0 0
    100 0 100 0 255 0
    
    예상 출력
    1686.851211072
    2724.913494800
    0.000000000