# Stretch a mesh between two points

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

## Recommended Posts

Hi,

Not sure if this should be in the maths section but since I'd like to use D3DX operations to achieve this, I've posted here.

Say I have a unit cube - a simple cube mesh 1 x 1 x 1 - and two points in 3d space.

I'd like to link the points with a 3d line made by transforming the cube.

Could anyone take me through the translation, rotation and scaling stages required to do this?

My thoughts:

Position cube midway between two points
Scale cube to height of distance between two points, and width of desired line
Perform a 3d rotation to match ends of stretched cube to two points

Its really the last operation I am having trouble with.

Thanks

Simon

##### Share on other sites
If you scale the height to match the distance between the 2 points, then the "up" vector of the cube has to be parallel (or anti-parallel) to the difference vector between the 2 points. Hence compute the difference vector, normalize it, and use that as up vector. Construct the other 2 vectors as usual, and compose all 3 vectors to yield in the rotation matrix. (Its just the same as computing a look-at matrix, for which dozens of threads can be found.)

Use the correct order of transformations: Scale the initial cube, rotate the scaled cube, translate the rotated and scaled cube.

##### Share on other sites
Quote:
 Original post by haegarrIts just the same as computing a look-at matrix

Nicely put, I hadn't looked at it like that

##### Share on other sites
You can simply use D3DXMatrixLookAtLH and inverse the result as described here

1. 1
2. 2
Rutin
25
3. 3
4. 4
5. 5

• 10
• 10
• 13
• 20
• 14
• ### Forum Statistics

• Total Topics
632946
• Total Posts
3009363
• ### Who's Online (See full list)

There are no registered users currently online

×