# Area of a Closed Bezier Curve - Graphics

This is a discussion on Area of a Closed Bezier Curve - Graphics ; Hi all, I need to evaluate the area of a closed cubic bezier curve defined by the list of control points ( num. points = 1 + 3 * num. bezier sub-curves ). I found a posible solution evaluating the ...

1. ## Area of a Closed Bezier Curve

Hi all,

I need to evaluate the area of a closed cubic bezier curve defined by
the list of control points ( num. points = 1 + 3 * num. bezier sub-curves ).

I found a posible solution evaluating the curve to get a polyline and
calculate the area of the enclosed area ( very simple ) but I'd like to
use a closed solution that doesn't depend on the number of points of the
polyline.

2. ## Re: Area of a Closed Bezier Curve

> Hi all,
>
> I need to evaluate the area of a closed cubic bezier curve defined by
> the list of control points ( num. points = 1 + 3 * num. bezier sub-curves ).
>
> I found a posible solution evaluating the curve to get a polyline and
> calculate the area of the enclosed area ( very simple ) but I'd like to
> use a closed solution that doesn't depend on the number of points of the
> polyline.
>

An interesting problem. For any piecewise differentiable curve in 2D,
the following general procedure gives you the area inside the curve /
series of curves. For polynomial curves (Bezier curves), you will get
closed form solutions.

Let
g(t) be a piecewise differentiable curve, with 0 <= t <= 1. g(t) is
oriented clockwise and g(1) = g(0).

Let
F(x, y) = [x, y] / 2

Then div(F(x, y)) = 1
where div is for divergence.

Now the divergence theorem gives you the area inside the closed curve g
(t) as a line integral along the curve:

int(dot(F(g(t)), perp(g'(t))) dt, t = 0..1)
= (1 / 2) * int(dot(g(t), perp(g'(t))) dt, t = 0..1)

perp(x, y) = (-y, x)

where int is for integration, ' for differentiation and dot for dot
product. The integration has to be pieced to the parts corresponding to
the smooth curve segments.

Now for examples. Take the Bezier degree 3 and one such curve with
control points (x0, y0), (x1, y1), (x2, y2), (x3, y3). The integral over
this curve is:

I := 3 / 10 * y1 * x0 - 3 / 20 * y1 * x2 -
3 / 20 * y1 * x3 - 3 / 10 * y0 * x1 -
3 / 20 * y0 * x2 - 1 / 20 * y0 * x3 +
3 / 20 * y2 * x0 + 3 / 20 * y2 * x1 -
3 / 10 * y2 * x3 + 1 / 20 * y3 * x0 +
3 / 20 * y3 * x1 + 3 / 10 * y3 * x2

Calculate this for each curve in the sequence and add them up. The sum
is the area enclosed by the curves (assuming the curves form a loop).

If the curve consists of just one Bezier curve, then it must be x3 = x0
and y3 = y0, and the area is:

Area := 3 / 20 * y1 * x0 - 3 / 20 * y1 * x2 -
3 / 20 * y0 * x1 + 3 / 20 * y0 * x2 -
3 / 20 * y2 * x0 + 3 / 20 * y2 * x1

Hope I did not do mistakes.

--
Kalle Rutanen
http://kaba.hilvi.org

3. ## Re: Area of a Closed Bezier Curve

found Gauss-Green Theorem, the same you explained to me.

Thanks Kalle..

4. ## Momentum of Inertia of a Closed Bezier Curve

Thanks Kalle. This works great !!

But I have another question: can I use the same approach to calculate
the momentum of inertia of the closed bezier curve ?

Let:

F(x,y) = [-x²y,xy²]

Then:

div(F(x,y)) = x²+y²

The integral (momentum of inertia) results:

I = int( dot( F(g(t)) , perp(g'(t) ) ) dt =
= int( -gx(t)²gy(t)d(gy(t))/dt + gx(t)gy(t)²d(gx(t))dt ) dt

Where:
g(t) = [gx(t),gy(t)]

Did I do any mistake ?

Kaba escribió:
>> Hi all,
>>
>> I need to evaluate the area of a closed cubic bezier curve defined by
>> the list of control points ( num. points = 1 + 3 * num. bezier sub-curves ).
>>
>> I found a posible solution evaluating the curve to get a polyline and
>> calculate the area of the enclosed area ( very simple ) but I'd like to
>> use a closed solution that doesn't depend on the number of points of the
>> polyline.
>>

>
> An interesting problem. For any piecewise differentiable curve in 2D,
> the following general procedure gives you the area inside the curve /
> series of curves. For polynomial curves (Bezier curves), you will get
> closed form solutions.
>
> Let
> g(t) be a piecewise differentiable curve, with 0 <= t <= 1. g(t) is
> oriented clockwise and g(1) = g(0).
>
> Let
> F(x, y) = [x, y] / 2
>
> Then div(F(x, y)) = 1
> where div is for divergence.
>
> Now the divergence theorem gives you the area inside the closed curve g
> (t) as a line integral along the curve:
>
> int(dot(F(g(t)), perp(g'(t))) dt, t = 0..1)
> = (1 / 2) * int(dot(g(t), perp(g'(t))) dt, t = 0..1)
>
> perp(x, y) = (-y, x)
>
> where int is for integration, ' for differentiation and dot for dot
> product. The integration has to be pieced to the parts corresponding to
> the smooth curve segments.
>
> Now for examples. Take the Bezier degree 3 and one such curve with
> control points (x0, y0), (x1, y1), (x2, y2), (x3, y3). The integral over
> this curve is:
>
> I := 3 / 10 * y1 * x0 - 3 / 20 * y1 * x2 -
> 3 / 20 * y1 * x3 - 3 / 10 * y0 * x1 -
> 3 / 20 * y0 * x2 - 1 / 20 * y0 * x3 +
> 3 / 20 * y2 * x0 + 3 / 20 * y2 * x1 -
> 3 / 10 * y2 * x3 + 1 / 20 * y3 * x0 +
> 3 / 20 * y3 * x1 + 3 / 10 * y3 * x2
>
> Calculate this for each curve in the sequence and add them up. The sum
> is the area enclosed by the curves (assuming the curves form a loop).
>
> If the curve consists of just one Bezier curve, then it must be x3 = x0
> and y3 = y0, and the area is:
>
> Area := 3 / 20 * y1 * x0 - 3 / 20 * y1 * x2 -
> 3 / 20 * y0 * x1 + 3 / 20 * y0 * x2 -
> 3 / 20 * y2 * x0 + 3 / 20 * y2 * x1
>
> Hope I did not do mistakes.
>

5. ## Re: Momentum of Inertia of a Closed Bezier Curve

> Thanks Kalle. This works great !!
>
> But I have another question: can I use the same approach to calculate
> the momentum of inertia of the closed bezier curve ?

You want to integrate x^2 + y^2 over the area enclosed by the Bezier
curve? Yes you can use the same approach as for any polynomial of x and
y.

> Let:
>
> F(x,y) = [-x²y,xy²]
>
> Then:
>
> div(F(x,y)) = x²+y²

There's a mistake here, the divergence of the given F is -2xy + 2xy = 0.
(div(F) = d(F)/dx + d(F)/dy)
The right F is
F(x, y) = [x^3, y^3] / 3

> The integral (momentum of inertia) results:
>
> I = int( dot( F(g(t)) , perp(g'(t) ) ) dt =
> = int( -gx(t)²gy(t)d(gy(t))/dt + gx(t)gy(t)²d(gx(t))dt ) dt
>
> Where:
> g(t) = [gx(t),gy(t)]
>
> Did I do any mistake ?

Try again with the new F

--
Kalle Rutanen
http://kaba.hilvi.org

6. ## Re: Area of a Closed Bezier Curve

> You made me remember some calculus theorems, searched on Google and
> found Gauss-Green Theorem, the same you explained to me.

Yes, although I haven't heard of Gauss-Green, just Gauss and Green
separately. They are very close to each other, yet I prefer Gauss
because it generalizes to higher dimensions. Greens theorem mixes the
actual idea and the computation of the normal that works only in 2D.

--
Kalle Rutanen
http://kaba.hilvi.org

7. ## Re: Momentum of Inertia of a Closed Bezier Curve

What a silly mistake !!.. Thanks Kaba. Now it works.

Kaba escribió:
>> Thanks Kalle. This works great !!
>>
>> But I have another question: can I use the same approach to calculate
>> the momentum of inertia of the closed bezier curve ?

>
> You want to integrate x^2 + y^2 over the area enclosed by the Bezier
> curve? Yes you can use the same approach as for any polynomial of x and
> y.
>
>> Let:
>>
>> F(x,y) = [-x²y,xy²]
>>
>> Then:
>>
>> div(F(x,y)) = x²+y²

>
> There's a mistake here, the divergence of the given F is -2xy + 2xy = 0.
> (div(F) = d(F)/dx + d(F)/dy)
> The right F is
> F(x, y) = [x^3, y^3] / 3
>
>> The integral (momentum of inertia) results:
>>
>> I = int( dot( F(g(t)) , perp(g'(t) ) ) dt =
>> = int( -gx(t)²gy(t)d(gy(t))/dt + gx(t)gy(t)²d(gx(t))dt ) dt
>>
>> Where:
>> g(t) = [gx(t),gy(t)]
>>
>> Did I do any mistake ?

>
> Try again with the new F
>