lookang
|
 |
«
Embed this message
on: November 26, 2008, 09:42:01 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE |
|
 Can explain what this do? I can't make sense of it Zero condition if(vy>0) return 1; // particle is not falling {what does return 1 mean?} which i found out later means do nothingreturn y; // displacement of particle above floor {why return y?} which i found out later means check for y = 0 to action Action Check box End step at event // action if particle is falling and below the floor vy = Math.abs(vy)*coef_of_restitution; {to return the value of Math.abs(vy)*coef_of_restitution to variable vy to simulate hitting n bouncing up like collision}ODE {Ordinary Differential Equations} page is dy/dt = vy and dvy/dt = - g thx for reply!
|
|
« Last Edit: November 26, 2008, 10:32:45 am by lookang »
|
Logged
|
|
|
|
lookang
|
 |
«
Embed this message
Reply #1 on: November 26, 2008, 10:29:49 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE |
|
 I found this http://www.um.es/fem/Download/Ejs/EjsManual_en_3.4_050914.pdf
|
|
« Last Edit: November 26, 2008, 10:35:33 am by lookang »
|
Logged
|
|
|
|
lookang
|
 |
«
Embed this message
Reply #2 on: November 26, 2008, 11:01:35 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE |
|
 i messed around the code to come up with this easy to understand codes if (y<-0.5) return y; // change the value to check where to rebounce example y<1.0 else return 1;i finally understand my own codes no worries! the original codes was confusing/misleading i think deeper meaning than i thought
|
|
« Last Edit: November 26, 2008, 02:40:05 pm by lookang »
|
Logged
|
|
|
|
Fu-Kwun Hwang
|
 |
«
Embed this message
Reply #3 on: November 26, 2008, 01:46:41 pm » posted from:Taipei,T'ai-pei,Taiwan |
|
 The original code if(vy>0) return 1; return y;
The above code is the same as if(vy>0) return 1; else return y; if(vy>0) it means that particle is moving upward, so there is no bouncing need to be take care of. otherwise, it will check if y is less than bouncing point y=0; You change the code to if(y<-0.5)return y; it mean that particle will bounced at y=-0.5 (not y=0).
|
|
|
Logged
|
|
|
|
lookang
|
 |
«
Embed this message
Reply #4 on: November 26, 2008, 02:27:52 pm » posted from:Singapore,,Singapore |
|
 The original code The above code is the same as if(vy>0) return 1; else return y;
if(vy>0) it means that particle is moving upward, so there is no bouncing need to be take care of. otherwise, it will check if y is less than bouncing point y=0;
Hi prof, In the examination of the original code, 1. what must be done to include a position of y to rebounce that is to be determine by user instead of the default of y = zero? Thx!  my codes doesn't work when y = 0.5 for example if (y<0.5) return y; // change the value to check where to rebounce example y<1.0
else return 1; // do nothing it still bounce at y = 0  strange
|
|
« Last Edit: November 26, 2008, 02:34:14 pm by lookang »
|
Logged
|
|
|
|
Fu-Kwun Hwang
|
 |
«
Embed this message
Reply #5 on: November 26, 2008, 05:27:49 pm » posted from:Taipei,T'ai-pei,Taiwan |
|
 If you want to have particle bounced at y=y0; (You can add a slider for user to change y0,too. ) you should change the code to if(vy>0)return 1; return y-y0; How it works in ejs: If the return value is less than zero, EJS will know it is an event need to be processed. And EJS will reduce time step to find the most precise point so that return value is almost equal to zero. process the event, and move forward the time to it should be. In your previous case, if(y<0.5)return y; you did not notice the error. Because the relative error is too small for your eye to notice it. However, the error will accumulate. If you change the range to y(maximum)=1 you will notice the error easily.
|
|
|
Logged
|
|
|
|
lookang
|
 |
«
Embed this message
Reply #6 on: November 27, 2008, 07:42:23 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE |
|
 if(vy>0)return 1; return y-y0;
Thanks! i go try it! so the syntax is "return y-y0". cool!
|
|
|
Logged
|
|
|
|
|