3d vectors calculation help please

Community Forums/General Help/3d vectors calculation help please

RemiD(Posted 2013) [#1]
Hello,

For my current project i have coded some routines to define the properties and the shape of corridors and rooms in an underground structure.

I have made good progress, but now i want to add more randomness to the Y position of each room.
Because between 2 rooms there is always a corridor starting from a passage in a room and ending in another passage in another room, as you can imagine, the corridor will have the vertices of the "start side" at one Y position and the vertices of the "end side" at a different Y position.
See :
[img]

[/img]

Now the challenge is that the corridor is made with 3d tiles subdivided meshes, and therefore there are many vertices that need to change position but i am not sure how to calculate the correct new position of each vertex depending on its old position and on the vector i know.

As you can see on the left illustration this is what the subdivided mesh of a corridor with a height of 3 and a length of 5 looks like when it has a flat ground.
It is simplified in order to not make it more confusing but for my project it is more subdivided than that (i want to have nice progressive shades for lighting)

As you can see on the right illustration, the vertices of the "end side" have a new Y position (0 was the old Y position, 0-0.75 is the new Y position)
So i know the Y position of the vertices of the "start side" (in green), and i know the Y position of the vertices of the "end side" (in red) because i know what is the Y position of the next room and the bottom vertices of the "end side" will be at the same Y position than the Y position of the next room.

Question : How to calculate the new Y position of the others vertices in the middle in order to have a progressive descent or ascent ? I think it is possible because i know the properties of the vector (in blue) from a vertex at the bottom on the "start side" to another vertex at the bottom on the "end side".

Maybe a possible approach would be to normalize the vector to 1 and then to multiply this vector by the distance from a vertex on a similar position on the "start side" to a vertex on a similar position on the "middle" and this will give the new position of the vertex in the middle. But it can be very confusing to retrieve which vertex has a similar position.

Another possible approach would be to calculate what is the length of the translation vector for each vertex and then i will be able to calculate the new Y position. But how ?

Any suggestions on how to do this ?

Thanks,

Last edited 2013


matibee(Posted 2013) [#2]
Ok let me see.. In your pic you have a green spot (origin O) and a red spot (destination D)

Assuming you know the initial drop (-0.75 in the case above)..

1) find the length of the vector OD (ie the distance between them)
2) divide the drop by that length to get a drop ratio

eg from your pic, length is 5, drop is -0.75
drop ratio is -0.75/5 = -0.15

3) for each new vertex between O and D, find the distance back to O and multiply that by the drop ratio

eg, vertex at 3 units
3 * -0.15 = -0.45


To get the distance between vertices O and D
dist = sqr( O.x * D.x + O.y * D.y + O.z * D.z )

Hope that helps


RemiD(Posted 2013) [#3]
Matibee>>Thanks i will try to use your explanations and see what it does.