# Centroid with Bezier

1. Jul 9, 2012

### jjj888

Does anyone have an easy formula for finding the centroid coordinates under a degree 3 bezier curve?

The whole parametric two variable thing isn't working with the formulas I know of.

Thanks

2. Jul 9, 2012

### AlephZero

See http://www.infogoaround.org/JBook/Inertia.html (inder "Green's Theorem").

You wouldn't really expect the formula to be "easy", since you can reparametrize a Bezier curve in arbitrary ways without changing its shape.

To do it numerically, interpolate points P1, P2, P3, etc along the curve and chop the area into triangles OP1P2, OP2P3, etc where O is the origin (or any other "fixed" point in the plane).

3. Jul 16, 2012

### jjj888

So,

Here's my parametric equations:

x = 3t
y = 5t^3-9t^2+6t

I get this when using that formula from the green's therom page:

X =∫(5x^3-9x^2+6x)^2*3dx = -2.657

Y = ∫(3y)^2(15y^2−18y+6)dy=2.25

int from 0 to 1.

x = 1.8
y = 0.7086

Which makes sense when you look at it.
I ran the equations through few other centroid formulas and I don't really get anything consitent. I can find the area pretty easy with parametic integration, but this centroid is giving me trouble.

Thanks

4. Jul 16, 2012

### chiro

Hey jjj888 and welcome to the forums.

It's going to be easier if you treat this as a centre of mass problem and assume that all points of the curve contribute evenly to the 'mass' of the function.

We know that to find the centroid you sum all of the values up and divide by the number of values in a discrete case. For the continuous case, we use the density function, but we assume that that the density is the same for all points.

So you have functions for x and y and given that the density is constant, how would you calculate the centroid from this?

5. Jul 17, 2012

### jjj888

If the density is constant you would use 1. But I read this somewhere else, and they said to just integrate my original functions normally, which also doesn't give me:
x=1.5
y=-1.25

6. Jul 17, 2012

### chiro

Assume your parameterization is [0,1] region.

Integrating 3tdt (since x = 3t) over [0,1] gives 3/2 = 1.5
Integrating 5t^3-9t^2+6t (since y = 5t^3-9t^2+6t) over [0,1] gives 1.25

These look like the answers above but the y value has the opposite sign.

7. Jul 17, 2012

### haruspex

Wouldn't the y co-ordinate of the centroid be ∫y.ds/∫ds, where ds2 = dx2+dy2? (And likewise x co-ord.) If so, ds will be dt*√(a quartic in t)

8. Jul 18, 2012

### jjj888

But,

As I said above, when I plot the curve out in CAD the centroid cordinates are:

x = 1.8
y = 0.7086

But I can't seem to get this answer. I'm fairly certain this answer is correct, it makes sense when you look at it. Very confusing at this point.

9. Jul 18, 2012

### chiro

One suggestion I have is to rederive the centroid using delta statements and take the limit to get the calculus definition, just to clarify what the expression should be.

10. Jul 18, 2012

### jjj888

you're going to have to break that down for me a bit.

11. Jul 18, 2012

### chiro

Well the centroid is the average of all data points and it is co-ordinate wise.

So lets say we do it with a spacing of deltax (dx is the limit as it goes to zero).

The continuous formulation is basically the analog of the expectation formula but there is slight difference: the difference is that the density refers to the number of points that take a particular value.

So to do this you need to break up the plots of all components (i.e. x and y) into sections that are increasing: you can use the first derivative to do this.

Then what you do is basically create a kind of 'histogram' of the density of the number of points in a bin with respect to all bins (each bin has the same height when you plot component against the parameter).

The bin size takes a limit argument to zero and you get a density function from all sections for each component. You then apply the expectation formula to that distribution you calculated where if f(x) gives the probability at x you calculate E[X].

This will give you the centroid.

If you want an approximation just a small enough bin size and this will give you a way to get a discrete distribution for each bin and then use the x value as the 'centre' of the bin and use E[X] for X being a discrete random variable.

12. Jul 19, 2012

### haruspex

OK, I misunderstood the problem. I thought you wanted the centroid of the curve. In fact, you want the centroid of the lamina bounded by that curve, the x-axis, the y-axis, and the line x = 3, yes?
Adx.dy = ∫t=01y(t).dx(t) = ∫(5t3-9t2+6t).3dt = 3[5t4/4-3t3+3t2]t=01 = 3(5/4-3+3) = 15/4
Ax.dx.dy = ∫3t(5t3-9t2+6t).3dt = 9∫(5t4-9t3+6t2).dt = 9[t5-9t4/4+2t3] = 9(1-9/4+2) = 27/4
xc = 9/5, agreeing with CAD.

13. Jul 31, 2012

### jjj888

Thanks,

I acctually did find the answer.

x = 3t
y = 5t^3-9t^2+6t

I got the answer using the formula below. This is the first formula I encountered when I started.

x=1/A∫abxf(x)dx
y=1/A∫ab(1/2)[f(x)]2dx

My error was with the area. I used the area under the curve of the parametric equations, but I should have used the area under f(x):

x=(1/1.25)∫01[3t(5t3-9t2+6t)]dt=1.8
y=(1/1.25)∫01(1/2)[(5t3-9t2+6t)2]dt=0.70857

Following the proof of the forluma it makes sence, but I'm still confused as to why it works with the parametric equations.

14. Jul 31, 2012

### chiro

Hey jjj888.

You are integrating with respect to each parameter and substituting those values in the integral and since they equivalent, they are giving the same answer. (i.e. y = f(x) = g(t) and x = other function of t).

What you can do if you want to formalize it is to do an integral substitution and see how the limits change from (a,b) to (0,1).

15. Aug 15, 2012

### jjj888

Ok so I'm adding on to this a bit.

I have:
x=0.9t3+5.1t2
y=-1.8t3-3.9t2+13.2t

using :
x=1/A∫abxf(x)dx
y=1/A∫ab(1/2)[f(x)]2dx

for centroid I get:
x=2.656
y=2.957

x=3.371
y=3.2872
which makes more sense

similarly I have:
x=-0.35t3-0.9t2+8.25t+6
y=4.4t3-6.6t2+7.5

for centroid I get:
x=9.496
y=3.246

x=9.2657
y=3.289

Wich is close but still not the same. Is there some issue with my integration bounds, or is it an issue with the area divisor? I've been playing with this for about a week and now I'm stuck.

Also, the two curves above link together, is there a way I can find the centroid for these two curves, (cad shows:x=6.6096,y=3.2882) how would I set it up if I had more?

Thanks

16. Aug 15, 2012

### chiro

Did you see haruspex's working out above?

17. Aug 15, 2012

### haruspex

Try writing out your derivation of the first x co-ord in detail (the 2.656) and I'll try to find the error. I get 125.59/37.26 = 3.37.

18. Aug 15, 2012

### jjj888

I did, but i wasn't too familiar with the notation. I'll take a look again.

19. Aug 16, 2012

### jjj888

I'm having trouble understanding how
xc = ∫Ax.dx.dy/∫Adx.dy is equal to x=1/A∫abxf(x)dx?

Anyway here's my x derivation using x=1/A∫abxf(x)dx:

x = 1/4.85∫01((0.9t3+5.1t2)(-1.8t3-3.9t2+13.2t)) = 2.656

I set it up the same way as the previous problem. I would think this is a fairly common problem, that is finding parametric equations to fit curves to things to calculate areas, centers, etc. It's strange I can't find more information about it out there. Obviously it's easily done with computers, but I just like to know how it works.

Thanks

20. Aug 16, 2012

### haruspex

Ax.dx.dy = ∫A.dy.x.dx = ∫xy.dy.x.dx = ∫xy.x.dx
What happened to dx? dx is (dx/dt)dt, not dt.
Let me illustrate just in calculating A:
A = ∫A.dy.dx = ∫xy.dy.dx = ∫xy.dx = ∫t y.(dx/tx).dt = ∫t (-1.8t3-3.9t2+13.2t).(2.7t2+10.2t).dt = 37.26