# Scaling matrix ofsetted from the origin

This topic is 3716 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How to build a scaling matrix, that scales an object that is not located at the orign, right now i'm sucbtracting every coordinate from the center, scale/rotate, and then translate back, i want to combine it one matrix. Paul

##### Share on other sites
Matrix multiply the scaling matrix M by translation matrix T and -T. I.e. OffsetedScale = T.M.(-T) where T translates the origin to the center. OffsetedScale will do everything you need. Of course, you will need homogeneous matrices for this.

##### Share on other sites
alMatrix4 mat1, mat2, mat3;		mat1.identity();			mat2.identity();		mat3.identity();		mat1.setTranslation(-m_position.getX(), -m_position.getY(), -m_position.getZ());	//translate to origin			mat2.scale(m_dragScale.getX(), m_dragScale.getY(), m_dragScale.getZ());				//scale		mat3.setTranslation(m_position.getX(), m_position.getY(), m_position.getZ());		//translate back		m_transformMat = mat1 *mat2*mat3 ;

i have this, can't seem to get it working, i have a plane on z=10, but it scales as well, only x and y should scale ,because (0,0, 10) is the the origin

##### Share on other sites
The principle is correct. The comment "translate to origin" should be "translate origin to 0", but obviously that doesn't influence the result very much ;)

The order of your matrix product is mat1*mat2*mat3 and hence hints at using row vectors. Do you use row vectors? If not, you have to use the reverse order mat3*mat2*mat1.

If [0,0,10] is the origin as is stored in m_position, then mat1 is set-up as translation by [0,0,-10]. Hence, any point [x,y,10] located at z=10 gets translated to [x,y,0] when being multiplied by mat1. Multiplying that z==0 by any number (due to the scaling) doesn't change it: 0*sz==0. Then the sub-sequent multiplication by mat3 translates the point back by [0,0,10] to [x*sx,y*sy,10]. q.e.d.

Quote:
 Original post by crowley9Matrix multiply the scaling matrix M by translation matrix T and -T. I.e. OffsetedScale = T.M.(-T) where T translates the origin to the center...

Here not the negative -T but the inverse T-1 is to be used. I know you presumbly meant the inverse
[ 1 0 0 -tx ][ 0 1 0 -ty ][ 0 0 1 -tz ][ 0 0 0  1  ]
but negating a matrix has itself a meaning which is different:
[ -1  0  0 -tx ][  0 -1  0 -ty ][  0  0 -1 -tz ][  0  0  0  -1 ]
So I wanted to make this point clear.

##### Share on other sites
it is working now, i've reversed the order mat3*mat2*mat1, and cleared the CACHE, this i morning i started with above order, but it gave me the same results nonetheless, after a full rebuild, it is working okay now, as well is translation and rotation. thanks guys

Paul

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633732
• Total Posts
3013584
×