Common area of a square and a Bézier curve

38 Views Asked by At

Find the common area of a region from a quadratic Bézier curve $$B(t)=(1-t)[(1-t)P_0 + t P_1] + t[(1-t)P_1 +t P_2], 0 \leq t \leq 1$$ (Where $$P_0, P_1, P_2$$ are 2-dimensional vectors representing points) to line segment P0 P2 and a square $$x_s - 0.5 \leq x \leq x_s + 0.5, y_s - 0.5 \leq y \leq y_s + 0.5$$

EDIT: So when the Bezier Curve is a line the area = 0. Let's assume the curve is not a line and $x_1 \ne \frac{x_0+x_2}{2}$ and $y_1 \ne \frac{y_0+y_2}{2}$: Let $A = d_0-2d_1+d_2$ and $B = d_1 - d_0$ where $d_n$ is either $x_n$ or $y_n$. (d is x) Let $$f(x)=\frac{-B \pm \sqrt{\max(0,B^2-A(x_0-x))}}{A}$$$$y(x)=f(x)^2(y_0-2y_1+y_2)+f(x)2(y_1-y_0)+y_0$$ y(x) is the formula for y of x with branches being the same constant when the result is complex which will not matter when calculating the area because we can subtract areas below those branches and they will cancel out. The antiderivative for this formula is $$(y_0−2y_1+y_2)I_2+(2y_1−2y_0)I_1+y_0x$$ where $$I_1=\frac{\pm 2(B^2-A(x_0-x))^{\frac{3}{2}} - 3ABx}{3A^2}$$ $$I_2=\frac{3(B^2-A(x_0-x))^2 \mp 8B(B^2-A(x_0-x))^{\frac{3}{2}}+6B^2Ax}{6A^3}$$ See this post

Y becames constant when $x=x_0-\frac{B^2}{A}$ The common points of the top/bottom of the square can be found by subtituting $x_n$s with $y_n$s and vice-versa and $x$ with $y$ of the sides. So finally we have 5 points and the formula to calculate area under the curve it looks like this on a graph:graph I can see a pattern for different parameters but I still haven't figured out an elegant method for determining which ranges of x has which function inside/over/below.