Q: calculate particle distance attrib vop

   5165   8   2
User Avatar
Member
2624 posts
Joined: Aug. 2006
Offline
Hi,
I am interested in being able to calculate the distance a particle travels as an exercise in attrib vop from a source pop . I thought this would be possible first by taking @v and calculating the length of the vector to give me the speed of the point. THen f@speed * f@timeinc = distance traveled but my distance values are tiny even though I can see over 1 meter has been covered.
Can anyone give me a pointer, I feel as if I must be missing something really simple.

Rob
Gone fishing
User Avatar
Member
25 posts
Joined: Oct. 2012
Offline
Using f@speed * f@timeinc = distance gives you the distance traveled over a single frame, your f@timeinc increment.
If you want the total distance you need to use your total timespan*speed.
If your velocity changes in between frames you could still use f@speed * f@timeinc = distance and keep adding that value to a total distance value.
User Avatar
Staff
6205 posts
Joined: July 2005
Offline
You may also considere using the pprevious…

@totaldist += distance(v@pprevious, @P);
User Avatar
Member
2624 posts
Joined: Aug. 2006
Offline
Thanks for guidance ! . just out of interest though if i want to do this entirely in pops I cannot see a global for @Nframes or @fps. I get the feeling I have to manually create

f@fps = 24;
f@nframes = 200;

f@totaltimespan = @nframes/@fps;

Rob
Gone fishing
User Avatar
Member
339 posts
Joined: Aug. 2007
Offline
Make a parameter and put $FEND in it.
Jesse Erickson
Fx Animator
WDAS
User Avatar
Member
2624 posts
Joined: Aug. 2006
Offline
Thanks, will have to refer how to make parms to display in the pop wrangle, thanks for the pointer. At least I know where to look ! .

Rob
Gone fishing
User Avatar
Staff
6205 posts
Joined: July 2005
Offline
Use a build of 14.0.227 or later.

Then in your popwrangel type:

f@totaltimespan = ch(“total_time”);

Then hit the little button that looks like a plug to the right of the multiline editor.

A parameter called Total Time will now be made, which that ch will refer to. In that parameter you can do your $NFRAME/$FPS.

You can also type

f@totaltimespan = $NFRAME/$FPS;

and it will work since we do global variable replacement in VEX strings. But I do not recommend that.
User Avatar
Member
2624 posts
Joined: Aug. 2006
Offline
Thanks !

// @TimeInc is a global variable
// @speed * @TimeInc = total distance travelled over 1 frame

f@speed = length(@v);
f@distperframe = f@speed * @TimeInc;
f@totaltimespan = ch("total_time");
f@totaldist = @totaltimespan*@speed;
//
f@test = @totaldist + @distperframe;/code]

Something is wrong with the initial solution. Jeff your solution works and gives me the correct numbers in the spreadsheet. but I can no reference to pprevious in the houdini help.

Rob
Gone fishing
User Avatar
Staff
6205 posts
Joined: July 2005
Offline
pprevious should be documented in the particle attribute list
http://www.sidefx.com/docs/houdini14.0/dopparticles/attributes [sidefx.com]

I'm a bit confused why your code is using f@tottaltimespan for this. It is causing it to be set to the total distance if the particle travelled at the current speed for all time. Usually you want to just integrate it, so I'd suggest


f@speed = length(@v); // dist per second
f@distperframe = @speed * @TimeInc; // Dist in this substep
f@totaldist += @distperframe; // Integrate


This may not give the same result as velocity does not always equal the movement over the frame. (An obvious example is a particle that bounces)

Another subtle point is that your distperframe isn't quite distance per frame. If you turn on substepping at the DOP or POP level it will be much smaller as it will just be the distance in this substep.
  • Quick Links