View Full Version : iterating through 2 inputMeshes
Aikiman 01062013, 03:45 AM Hi there,
Im making a plugin where I want to compute the velocity of points on a mesh that are deforming. So I have an input for the meshOriginal and another for the finalMesh. The problem is the logic I am using, I know its just wrong but I can think of another way to do it.
Currently I believe I am grabbing the first point on mesh1 and then computing it with every point on mesh2, once thats done the same thing happens for the second point. This is wrong.
All I want to do is to compute mesh1Point1 with mesh2Point1, then mesh1Point2 with mesh2Point2 etc etc. Heres the code I have so far, any help would be grateful.
while not meshIter1.isDone():
point1 = meshIter1.position( om.MSpace.kWorld )
while not meshIter2.isDone():
point2 = meshIter2.position( om.MSpace.kWorld )
vector = om.MVector( point2  point1 )
outVectArray.append( vector )
meshIter2.next()
meshIter1.next()


sciLoop
01062013, 09:23 AM
I`m not sure if I understood your question.
If you want interactive feedback you should save the position of every vertex for every evaluation cycle and compare the last with the current position.
Is it that what you want?
zoharl
01062013, 11:44 AM
while not meshIter1.isDone() and not meshIter2.isDone():
point1 = meshIter1.position( om.MSpace.kWorld )
point2 = meshIter2.position( om.MSpace.kWorld )
vector = om.MVector( point2  point1 )
outVectArray.append( vector )
meshIter2.next()
meshIter1.next()
The norm of each vector divided by the time would give you the velocity.
Aikiman
01062013, 09:48 PM
while not meshIter1.isDone() and not meshIter2.isDone():
point1 = meshIter1.position( om.MSpace.kWorld )
point2 = meshIter2.position( om.MSpace.kWorld )
vector = om.MVector( point2  point1 )
outVectArray.append( vector )
meshIter2.next()
meshIter1.next()
The norm of each vector divided by the time would give you the velocity.
Ahh simple as that thank you but now I realise my method is wrong. I need the point position from the current frame and the frame before rather than use the meshShapeOrig as input  silly mistake. Ill give that a go now.
Can you explain a bit more about the norm of each vector? Do you mean the normalised vector result of point2point1? What about the magnitude?
zoharl
01062013, 10:16 PM
Norm is the magnitude (L2 norm of a vector equals to the vector's length). Normalizing a vector means dividing it by its norm (and then its norm  length  is 1).
http://mathworld.wolfram.com/VectorNorm.html
zoharl
01062013, 11:00 PM
I had a power failure (I live in a banana republic...), so I didn't finish editing my post.
About the velocity. The norm of the vector would give us the distance between two points, so we have the distance as a function of time. From elementary school, we know that the derivative of the distance function (w.r.t. time) is the velocity. You have samples of the distance functions (as the vertices of your meshes), and you want to approximated the derivative of the distance function using finite difference. But first you need specify where/when (in which point in space or time) do you want to calculate the velocity. . In you first post you suggested approximating the velocity with forwarddifference of order 0: (x_{t+1}x_t), where \Delta t, the time step, is 1. In the previous post you suggested to approximate the velocity using centraldifference of order 0: (x_{t+1}x_{t1})/2. You can actually use more samples (as much as you like), and raise the approximation order (how precise your estimation is), by plugging your samples into the appropriate formula:
http://en.wikipedia.org/wiki/Finite_difference
But I didn't try this in practice, so you should ask someone from dynamics how crucial the order of approximation is.
Aikiman
01072013, 08:42 AM
Okay I was getting myself confused with norm and normalize for a moment. Unfortunately math isnt my strong point, I understand basic trig and vector math but calculus  forget it ;)
zoharl
01082013, 06:31 AM
You implied it was too simple... ;)
Never mind, do it like your intuition tells you. Divide the length (distance) by the time, and you get the velocity.
Aikiman
01082013, 10:45 PM
Ill give myself a couple of points for the enthusiasm ;)
Thanks for your help.
Aikiman
01092013, 08:06 PM
Okay Ive given this a few more moments of thought in between other projects. If the evaluation of velocity happens every frame that would mean time is constant right, ie every frame? That would mean all I need is the distance per frame ie point2  point1 as in the above code you supplied earlier?
zoharl
01102013, 01:55 AM
Exactly. If you have three consecutive frames at time t0, t1, t2, with a uniform time step dt, and you want the velocity v1 (for time t1) at a mesh vertex with given point coordinates for each frame x0, x1, x2, then as you said before, each of the three options is legit:
1. v1 = (x2x1)/dt
2. v1 = (x1x0)/dt
3. v1 = (x2x0)/(2dt)
where xixj is the distance (vector length, norm) between point xi and xj.
CGTalk Moderation
01102013, 01:55 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.