# Path Center Correction

So I have groups of (x,y) coordinates that I'm using to draw lines. The lines aren't perfectly straight but they are connected.

In a Cartesian plane the middle would be called the origin, but I'm working with a digital image processing program, so the coordinate (0,0) is at the top left of the image.

What I'm trying to do is translate all of the coordinates in each line (group of coordinates) the same distance, so that the first point in each line starts at the middle of the image.

Here is an example of what I want:

Here is what I have:

• So what's your question? – Jim Clay Jun 25 '12 at 17:43
• So you actually have a group of points (first point in each line) and you want to translate each of them to the origin keeping the size of translation vector constant (though orientation can change for each line)? If so, you this does not have a general solution, since every point have different distance from the origin (in general) and there is only one unique translation vector for each point, namely $(-x, -y)$, given that the origin is at $(0,0)$. Its length is varying from point to point. Am I missing something? – Libor Jun 25 '12 at 17:48
• Maybe you want to translate centroid of the path? But in such case there is only one translation vector for all the points. Please clarify you question. – Libor Jun 25 '12 at 17:51
• @Libor That is correct, except I cannot call the point the origin because in my coordinate plane it is just the middle of the image. – Alex W Jun 25 '12 at 19:30
• @JimClay It is in bold type. – Alex W Jun 25 '12 at 19:30

1) Group of points: $\{ (x_{i},y_{i})\}_{i=1..n}$

2) Centroid of the group of points: $\left(\frac{1}{n} \sum^{n}_{i=1}x_{i},\frac{1}{n}\sum^{n}_{i=1}y_{i} \right)$.

3) Center of the image: $(x_{c},y_{c})$

4) Translation of arbitrary point $(x,y)$ to the center $(x_{c},y_{c})$: $t(x,y)=(x_{c}-x,y_{c}-y)$

Note that $(x,y)+t(x,y) = (x_{c},y_{c})$ ...

Now just substitute 2) in 4) and you have your formula to translate the centroid to the image center. Right?

I am sure that I am missing something here - the translation distance obviously cannot be kept the same for all points. Didn't you mean another type of transform (maybe scaling have to be included as well) ?

• I'll try these forumulas. The kicker here is that the center of my image is not (0,0) like it would be in a regular Cartesian plane. The center coordinate is (image width /2, image height /2). For example: a 512x512 image, the center would be (256,256). – Alex W Jun 25 '12 at 19:58
• Well it doesn't matter where the origin is. If you want the origin to be at $(0,0)$ you can simply shift all the points by $(-w/2,-h/2)$, do the work and then shift it back by $(w/2,h/2)$. But when it comes to simple translation, you can compute the centroid, find its shift to $(x_{c},y_{c})$ and then apply the shift to every point. It is indeed very simple. – Libor Jun 26 '12 at 10:56
• Ok using that equation, I have drawn out all of the centroids as ovals: freeimagehosting.net/newuploads/2yt8c.jpg . Should I translate each centroid to the middle of the image? – Alex W Jun 26 '12 at 14:06
• Thanks. The centroid equation was really helpful in getting my final product. – Alex W Jun 26 '12 at 18:24