2
$\begingroup$

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:

enter image description here

Here is what I have:

enter image description here

$\endgroup$
  • 1
    $\begingroup$ So what's your question? $\endgroup$ – Jim Clay Jun 25 '12 at 17:43
  • $\begingroup$ 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? $\endgroup$ – Libor Jun 25 '12 at 17:48
  • $\begingroup$ 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. $\endgroup$ – Libor Jun 25 '12 at 17:51
  • $\begingroup$ @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. $\endgroup$ – Alex W Jun 25 '12 at 19:30
  • $\begingroup$ @JimClay It is in bold type. $\endgroup$ – Alex W Jun 25 '12 at 19:30
2
$\begingroup$

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) ?

$\endgroup$
  • $\begingroup$ 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). $\endgroup$ – Alex W Jun 25 '12 at 19:58
  • $\begingroup$ 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. $\endgroup$ – Libor Jun 26 '12 at 10:56
  • $\begingroup$ 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? $\endgroup$ – Alex W Jun 26 '12 at 14:06
  • $\begingroup$ Thanks. The centroid equation was really helpful in getting my final product. $\endgroup$ – Alex W Jun 26 '12 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.