Author Topic: relations between displacement/velocity/acceleration  (Read 50152 times)

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: relations between displacement/velocity/acceleration
« Reply #15 on: July 16, 2008, 04:14:59 pm »
Define a variable e.g. id and set property "element" for particleSet to id.
When user drag one of the particle, the id will contain the index for the particle.
id will be -1 if none of them were dragged.

i followed the "set property "element" for particleSet to id."

but i monitor the value of id, it is always zero.

what am i doing wrong :)

the rest of the code works! but because the "set property "element" for particleSet to id." didn't work, only the yv[0] works now.

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: relations between displacement/velocity/acceleration
« Reply #16 on: July 16, 2008, 05:11:09 pm »
no worries, i finally figure out

In Models - Variables
i assign a new variable
j integer type

In Models - Custom
i added a new function called dsnap()
public void dsnap () {

// for(int i=0;i 
//yv[i] = yv[i] - (yv[i]%1.0); // for future used change %1.0 to %0.5 if want snap to 0.5 :)

 if(j>-1) yv[j]=(double)((int)yv[j]);

In View
Polygon
Point Selected assign that to the earlier declared variable j
On Drag add the new function as follows
dragvt();
dsnap();


Debugging purpose:
Add a new field, variable j format "j = 0.0"

works now........no to worry!

« Last Edit: July 16, 2008, 05:48:36 pm by lookang »

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: relations between displacement/velocity/acceleration
« Reply #17 on: July 16, 2008, 09:38:15 pm »
Yes. You need to define variable in the model. Normally, I will define a variable named "id";

And I will add code like:
if(id>-1) yv[id]=(double)((int)yv[id]);
in the drag action field.

Please add id>-1 , because id equal to -1 when none of the element was selected.

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web