# iterating through 2 inputMeshes

 01 January 2013 Aikiman Pixel Collisions   portfolio Jeremy Raven Wellington, New Zealand iterating through 2 inputMeshes 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()`````` __________________ Vimeo Last edited by Aikiman : 01 January 2013 at 06:45 AM. share quote
 01 January 2013 sciLoop Expert   portfolio Burkhard Rammner bioinformatition med.uni.goettingen/sciloop Hamburg, Germany 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? share quote
 01 January 2013 zoharl A newbie   portfolio Zohar Wellington, New Zealand ``````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. share quote
 01 January 2013 Aikiman Pixel Collisions   portfolio Jeremy Raven Wellington, New Zealand Originally Posted by zoharl: ``````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 point2-point1? What about the magnitude? __________________ Vimeo share quote
 01 January 2013 zoharl A newbie   portfolio Zohar Wellington, New Zealand 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 share quote
 01 January 2013 zoharl A newbie   portfolio Zohar Wellington, New Zealand 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 forward-difference 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 central-difference of order 0: (x_{t+1}-x_{t-1})/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. share quote
 01 January 2013 Aikiman Pixel Collisions   portfolio Jeremy Raven Wellington, New Zealand 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 __________________ Vimeo share quote
 01 January 2013 zoharl A newbie   portfolio Zohar Wellington, New Zealand 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. share quote
 01 January 2013 Aikiman Pixel Collisions   portfolio Jeremy Raven Wellington, New Zealand Ill give myself a couple of points for the enthusiasm Thanks for your help. __________________ Vimeo share quote
 01 January 2013 Aikiman Pixel Collisions   portfolio Jeremy Raven Wellington, New Zealand 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? __________________ Vimeo share quote
 01 January 2013 zoharl A newbie   portfolio Zohar Wellington, New Zealand 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 = (|x2-x1|)/dt 2. v1 = (|x1-x0|)/dt 3. v1 = (|x2-x0|)/(2dt) where |xi-xj| is the distance (vector length, norm) between point xi and xj. share quote
 01 January 2013 CGTalk Moderation Expert Thread automatically closed 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. __________________ CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.
Forum Jump
 Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Gallery     CG Awards     Featured 2D     Featured 3D     Latest Entries Main     News     General Discussion     Featured Videos     Education     Off Topic     Recruitment         Temp Job Board Challenges     CGSociety/IAMAG Beyond the Wall     Stylized Environment Challenge     Lighting Challenges     Professional Feedback Software     Autodesk Maya         Maya Dynamics         Maya Rendering         Maya Character Setup         Maya Programming     Autodesk Miscellaneous         Autodesk MotionBuilder         Autodesk Mudbox         Autodesk Softimage             XSI: Programming             ICE: Interactive Creative Environment     Autodesk 3ds max         3dsMax Tutorials & Tips         3dsMax Resources         3dsMax SDK and MaxScript         Plugins & Add-ons         Particle Flow     Maxon Cinema 4D         Cinema 4D Resources     The Foundry Modo         The Foundry Time Travel Challenge     Pixologic ZBrush     Photoshop / Painter     Side Effects Houdini     Blender     Lightwave 3D         LW Resources         LW Tutorials     Allegorithmic Substance         Substance Designer         Substance Painter     E-on Software Vue     Compositing Software         The Foundry Nuke         Adobe After Effects         Autodesk Effects and Compositing         Eyeon Software Digital Fusion WIP     WIP/Critique: 3D     WIP/Critique: 2D         Speedpaints & Sketchbooks     WIP/Critique: Animation     Collaborative Projects Techniques     Art Techniques and Theories     Digital Matte Painting         Digital Matte Painting Mini-Challenge     Modeling         Modeling Challenge             Member Model Collection     Texturing and Surfacing     Character Rigging     Animation     Lighting and Shaders     Compositing and Editing     Anatomy and Figurative Art         SPOTLIGHT: Best of the Artistic Anatomy and Figurative Art Forum         Tutorials and Workshops         Personal Anatomy & Sketchbook Threads         References, Resources, and Supplies Technical     VR/AR     Game Engine     Graphics Programming     Technical and Hardware
Miscellaneous

All times are GMT. The time now is 02:41 PM.