NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
November 01, 2014, 07:25:38 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
You cannot always have happiness but you can always give happiness. ..."Mother Teresa(1910-1997, Roman Catholic Missionary, 1979 Nobel Peace Prize)"
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: how to have detection difference when touch from below and from inside the jaws?  (Read 8793 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
on: November 25, 2009, 06:40:57 pm »

reference:
http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=684.0

Hi Ejs community, chance to give some tips how to implement
 when the blue object (centre is ox,oy) with height h and width w is hitting the lower tip of the inner jaws ( oxmin,oymin) for example that it will be blocked?

my existing strategy adapted from http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1189 uses the condition (ox<=oxmin+w/2&&oy>oymin-h/2) { // check left boundary true to make blue object fit into the jaws ox=oxmin+w/2; which is necessary when it is inside the jaws say oy>oymin-h/2.
but i can't figure out a way to make the boundary detection different from below and when inside the jaws because i am stuck cos both conditions i am using (ox<=oxmin+w/2&&oy>oymin-h/2)
chance to help?
Thanks!
the picture for the context of understanding the codes below
my object codes
// to check boundary of blue object with the parts of the vernier caliper
if(ox<=oxmin+w/2&&oy>oymin-h/2) { // check left boundary true

ox=oxmin+w/2;

if(x2+x<=ox+w/2&&oy>oymin-h/2){ // check object and jaws to stop motion&& object y above object y minimum

x=w;
}

}
if(x<0)x=0; // for the 2 jaws to meet at zero


else if((ox>x2+x-w/2)&& (oy>oymin-h/2) &&  (oy < oymax-h/2) ){ // right jaw hit object and inside jaws

   ox=x2+x-w/2; // to force the blue object into the open jaws
}

if(oy>oymax-h/2)oy=oymax-h/2; // check top boundary codes changes to suit lookang thinking


* Screen shot 2009-11-25 at PM 07.31.03.png (75.75 KB, 949x600 - viewed 273 times.)

*** There are 1 more attached files. You need to login to acces it!
« Last Edit: November 25, 2009, 06:50:34 pm by lookang » Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #1 on: November 26, 2009, 04:08:18 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

after discussion with my friends
it seems that suggestion could be

if( ox < oxmin && oy < oymin )oy=oymin-h/2; // check boundary codes of blue object top side hitting the left jaw

trying not to nest the codes for ease of debugging.

will try later at home Smiley

need the feedback from the Ejs simulation to refine the codes further
« Last Edit: November 26, 2009, 04:10:46 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3057



WWW
«
Embed this message
Reply #2 on: November 26, 2009, 04:10:53 pm » posted from:Taipei,T\'ai-pei,Taiwan

To check if the blue object is hitting the inner jar located at (oxmin, oymin).

1. check for y direction: it will only occurs if oy+h/2 >= oymin;
2. check for x direction: ox-w/2 <= oxmin and ox+w/2>=oxmax
 the above conditions can be combined with (ox-w/2-oxmin)*(ox+w/2-oxmax)<=0

The above two conditions need to be satisfied at the same with (with and operator; &&)
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #3 on: November 28, 2009, 08:57:32 pm »

after much testing and more testing and more testing,
i realize the codes need to be inside the blue object on drag.

i came up with these codes but it is still not ideal. the problem is it still runs the "detect bottom codes" when it is running the "inside codes". any help is greatly appreciated Grin
This problem i am facing is due to my inability to code the conditions "detect bottom codes" differently as "inside codes". Any tips? I try to create knowledge by doing, but it is difficult without your help! Cheesy

if (( ox-w/2-oxmin)*(ox+w/2-oxmax)>0&&(oy+h/2-oymin)*(oy+h/2-oymax)<0){ // "detect bottom codes" suggestion by wolfgang method by hwang to detect outside the jaws
oy = oymin-h/2; // force blue object to be fixed just below jaw
}

if ((ox-w/2-oxmin)*(ox+w/2-oxmax)<=0 &&oy+h/2 >= oymin){ // "inside codes" detect inside jaws
  if ( (ox-w/2-oxmin)<=0) // if exceed into the left jaw
  {
   ox=oxmin+w/2; // force blue object to sit by the side of left jaw
   }
  if ((ox+w/2-oxmax)>=0) // if exceed into the right jaw
  {
   ox=oxmax+w/2; // force blue object to sit by the side of right jaw
   }
   }


*** There are 1 more attached files. You need to login to acces it!
« Last Edit: November 28, 2009, 09:05:20 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3057



WWW
«
Embed this message
Reply #4 on: November 28, 2009, 11:21:05 pm » posted from:Taipei,T'ai-pei,Taiwan

add a variable out=true; as default (type= boolean)
if(ox+w/2>oxmax)ox=oxmax-w/2;
if(out){
 if(ox-w/2<oxmin && oy+h/2>oymin)oy=oymin;
 if(ox-w/2>=oxmin && ox+w/2<=oxmax && oy+h/2>oymin)out=false;
}else{
 if(ox-w/2<oxmin)ox=oxmin+w/2;
 if(ox+w/2>oxmax)ox=oxmax-w/2;
 if(oy+h/2>oymax)oy=oymax-h/2;
}



Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #5 on: November 29, 2009, 09:37:06 am »

Thanks!
i will continue to refine, i got some parts working now and some parts not working the way i wanted.

need more time and determination to examine what every line of code is doing so as to improve it until i am satisfied.

the code that helped is. i am still working on it but for the rest of the people i think this is the code that " detection difference when touch from below and from inside the jaws?"

// idea from http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1313.msg5065;topicseen#msg5065
// need the -+20 dragging blue object to hard into jaws when blue object is drag to ensure outobject=false when inside
 if(ox-w/2 > oxmin-20 && ox+w/2 < oxmax+20 && oy+h/2 > oymin)outobject=false;
 else outobject = true;

gotta balance family needs on sundays Grin


*** There are 1 more attached files. You need to login to acces it!
« Last Edit: November 29, 2009, 09:40:52 am by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3057



WWW
«
Embed this message
Reply #6 on: November 29, 2009, 10:41:32 am » posted from:Taipei,T\'ai-pei,Taiwan

If you use the above condition object inside/outside an area, you need another way to find out if user drag object into/out of that area.

Some more code need to be added to my previous replied message:

if(ox+w/2>oxmax)ox=oxmax-w/2;
if(out){
 if(ox-w/2<oxmin && oy+h/2>oymin)oy=oymin;
 if(ox-w/2>=oxmin && ox+w/2<=oxmax && oy+h/2>oymin)out=false;// move into hot area
}else{
 if(ox-w/2<oxmin)ox=oxmin+w/2;
 if(ox+w/2>oxmax)ox=oxmax-w/2;
 if(oy+h/2>oymax)oy=oymax-h/2;
 if(ox-w/2>=oxmin && ox+w/2<=oxmax && oy-h/2>oymin)out=true; // move out of hot area
}

Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #7 on: November 29, 2009, 05:13:43 pm »

Thanks prof hwang, ur ideas helped give me the tools to experiment with the codes until i got this. I must thank you for your support even on Saturday and Sunday because u made a difference in my learning!
this web2.0 forum is super cool, better than email because everyone else can learn, emails get lost in cyberspace after some time.

The codes seems to work reasonable well most of the times for blue object on drag

// use 2000 instead of 0 for realistic boundary detection
if (( ox-w/2-oxmin)*(ox+w/2-oxmax) > 2000 && (oy+h/2-oymin)*(oy+h/2-oymax) < 0 && outobject == true){ // "detect bottom codes" suggestion by wolfgang method by hwang to detect outside the jaws

oy = oymin-h/2; // force blue object to be fixed just below jaw
}

if (x < w && outobject == true && (oy+h/2-oymin) > 0){ // jaw too narrow for object

oy = oymin-h/2; // force blue object to be fixed just below jaw
}

// use 2000 instead of 0 for overcoming the blue object at the very top
if ((ox-w/2-oxmin)*(ox+w/2-oxmax) <= 5000 && oy+h/2 - oymin >= 0 && outobject==false){ // "inside codes" detect inside jaws
  if ( (ox-w/2-oxmin)<= 0) // if exceed into the left jaw
 {
   ox=oxmin+w/2; // force blue object to sit by the side of left jaw
  }
  if ((ox+w/2-oxmax) >= 0) // if exceed into the right jaw
  {
   ox=oxmax-w/2; // force blue object to sit by the side of right jaw
   }
   }

http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=684. has the new blue object codes, check it out Wink
« Last Edit: November 29, 2009, 05:22:33 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3057



WWW
«
Embed this message
Reply #8 on: November 30, 2009, 08:46:44 am » posted from:Taipei,T\'ai-pei,Taiwan

I download your code and modified it.
I remove drag action in objectblue, disable objectnewdesign and add objectnewdesignFKH.
Code:
oxmax=oxmin+x;
if(w>x){
  if(oy>oymin-h/2)oy=oymin-h/2;
  outobject=true;
}else{// object is smaller than the width
 if(outobject){// if object is outside do the following check
  if(ox-w/2>oxmin && ox+w/2<oxmax && oy+h/2>oymin){// move inside
  outobject=false;
  }else{
  if(ox-w/2<oxmin || ox+w/2>oxmax){
  if(oy+h/2>oymin)oy=oymin-h/2;
  }
  }
 }else{// if object is inside do the following check
  if(oy+h/2<oymin)outobject=true;// move outside again
  else{
  if(oy+h/2>oymax)oy=oymax-h/2;
  if(ox-w/2<oxmin)ox=oxmin+w/2;
  else if(ox+w/2>oxmax)ox=oxmax-w/2;
  }
 } 
}

The result is the following

Embed a running copy of this simulation

Embed a running copy link(show simulation in a popuped window)
Full screen applet or Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
Press the Alt key and the left mouse button to drag the applet off the browser and onto the desktop. This work is licensed under a Creative Commons Attribution 2.5 Taiwan License
  • Please feel free to post your ideas about how to use the simulation for better teaching and learning.
  • Post questions to be asked to help students to think, to explore.
  • Upload worksheets as attached files to share with more users.
Let's work together. We can help more users understand physics conceptually and enjoy the fun of learning physics!
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #9 on: November 30, 2009, 01:32:16 pm » posted from:Singapore,,Singapore

this is excellent prof hwang.

i think i will keep your codes instead of using my codes.

yours is more refined, mine got some problems when the mouse is moving all over screen LOL.

thanks!, your r the best. hahahaha

btw, there is a bug still in your codes, when the blue object is inside the jaws, on closing the jaws, when the x
easily fixed, i try to edit them now?
« Last Edit: November 30, 2009, 01:38:12 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3057



WWW
«
Embed this message
Reply #10 on: November 30, 2009, 08:28:54 pm » posted from:Taipei,T\'ai-pei,Taiwan

Move the above code to "drag action in objectblue" should solve the problem.
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #11 on: November 30, 2009, 10:39:44 pm »

thanks!

just for ur info
i copied into the on drag action of the blue object the codes from objectnewdesignFKH, the same thing the blue object pops down when the jaws are meeting the blue object.

so what i did was i disabled objectnewdesignFKH

and enabled back the working codes from objectnewdesign....and the bug is gone!

i think the codes u made in  objectnewdesignFKH need to be inside the blue object while the codes

.....................
else if((ox>x2+x-w/2)&&(oy>oymin-h/2)&&(oy<=oymax-h/2)){ // right jaw hit object and inside jaws

  ox=x2+x-w/2; // to force the blue object into the open jaws
}

solved the bug.

the new applet will be hosted there http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=684.msg2452#msg2452

thanks for taking the your applet to the next level for usability in improving learning Grin.
Logged
Pages: [1]   Go Up
  Print  
You cannot always have happiness but you can always give happiness. ..."Mother Teresa(1910-1997, Roman Catholic Missionary, 1979 Nobel Peace Prize)"
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Mirage! you can see it but you can not touch it!
Optics
Fu-Kwun Hwang 6 28847 Last post January 28, 2012, 06:07:25 pm
by 1001obiavi
production and detection of AM waves
Misc
bhavin365 1 15154 Last post October 31, 2005, 08:56:42 am
by Fu-Kwun Hwang
Mirage! you can see it but you can not touch it!
optics
ahmedelshfie 0 1988 Last post May 22, 2010, 01:56:22 am
by ahmedelshfie
Transverse wave and phase difference
Collaborative Community of EJS
LeeTl 1 3630 Last post April 16, 2013, 10:11:54 am
by lookang
Longitudinal wave and phase difference
Collaborative Community of EJS
LeeTl 3 2189 Last post April 16, 2013, 10:09:20 am
by lookang
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.059 seconds with 22 queries.since 2011/06/15