How to apply a translation to a coordinate vector?

Viewed 55

I am trying to implement and understand how to perform a simple translation in GLSL. In order to do that, I am making a simple test in Octave to ensure that I am understanding the transformation itself.

I have the following vector that represents a 2D coordinates embedded into a 4 dimension vector:

candle = [1586266800, 11812, 0, 0]

Which means that the point has locations x=1586266800 and y=11812.

I am trying to apply a translation using the following values:

priceBottom = 11800
timestampOrigin = 1586266800

Which means that the new origin of coordinates will be x=1586266800 and y=11800.

I build the following translation matrix:

[ 1 0 0 tx ]
[ 0 1 0 ty ]
[ 0 0 1 tz ]
[ 0 0 0 1  ]

translation1 = [1, 0, 0, -timestampOrigin; 0, 1, 0, -priceBottom; 0, 0, 1, 0; 0, 0, 0, 1]

Is this matrix correct? How shall I apply it to the vector?

I have tried:

>> candle * translation1
ans =
1.5863e+009  1.1812e+004  0.0000e+000  -2.5162e+018

Which obviously does not work.

1 Answers

Your translation is wrong. From a mathematical point of view, the transformation you're after is:

i.e. you need to 'augment' your vector with another dimension with the value 1, so that it can be used to add the 'translation' information to each row during matrix multiplication.

So, if I understood your example correctly

Initial_position   = [1586266800; 11812; 0; 0]   # note: vertical vector
Augmented_vector   = [Initial_position; 1]
Translation_vector = [0         ; -12  ; 0; 0]   # note: vertical vector

Transformation = eye(5);
Transformation( 1:4, 5 ) = Translation_vector

Translated_vector = Transformation * Augmented_vector;
Translated_vector = Translated_vector( 1:4, 1 )
Related