NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
December 13, 2017, 04:42:06 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Teaching without words. ...Lao Tzu (570-490 BC)
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 make an applet that is controlled by F (length) and angle (cta)  (Read 8040 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
on: March 02, 2009, 08:34:11 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE

i am currently trying to mimic the functions of

http://www.walter-fendt.de/ph14e/forceresol.htm
© Walter Fendt, May 30, 2003
Last modification: July 1, 2003


I used http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=634.msg2195#msg2195

to construct this http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1018.msg3713#msg3713

at this moment the applet derived from yours Smiley can do this!

Fixed relations:
xp=x+Math.sqrt(dx2*dx2+dy2*dy2)*Math.cos(Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))*Math.cos(Math.atan2(dy1,dx1));
yp=y+Math.sqrt(dx2*dx2+dy2*dy2)*Math.cos(Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))*Math.sin(Math.atan2(dy1,dx1)); 

i notice i changed the codes to take values of dx2,dy2,dx1 and dy1 to find xp and xp ( the coordinate of the component of the FORCE (black line) on the BLUE line.

The current programmed applet works fine, but i can't figure out a way to make the applet to be controlled by F (length) and angle (cta) like the
http://www.walter-fendt.de/ph14e/forceresol.htm


I am guessing i need to change and rewrite the codes to use F and cta bearing in mind that i still want to applet to allow the black line to be draggable which i notice is determined by the size x and size y and i noticed if i use size x = F*Math.cos(cta) and size y = F*Math.sin(cta), the applet is no longer draggable Huh I am struck here Angry

any tips how i can mimic  http://www.walter-fendt.de/ph14e/forceresol.htm ability to allow F draggable and still can resolve components which your source codes allows me to built on.


*** There are 1 more attached files. You need to login to acces it!
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #1 on: March 02, 2009, 11:03:48 am »

Quote
Fixed relations:
xp=x+Math.sqrt(dx2*dx2+dy2*dy2)*Math.cos(Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))*Math.cos(Math.atan2(dy1,dx1));
yp=y+Math.sqrt(dx2*dx2+dy2*dy2)*Math.cos(Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))*Math.sin(Math.atan2(dy1,dx1)); 
The above method fixed xp and yp at any momentum, because you tell EJS to do so.
If you want xp and yp controlled by more than one method, you could move the above code to a function
Code:
public void drag(){
xp=x+Math.sqrt(dx2*dx2+dy2*dy2)*Math.cos(Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))*Math.cos(Math.atan2(dy1,dx1));
yp=y+Math.sqrt(dx2*dx2+dy2*dy2)*Math.cos(Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))*Math.sin(Math.atan2(dy1,dx1)); 
}
and add drag() to action property when dx1,dy1 or dx2,dy2 arrows are dragged.

Quote
x = F*Math.cos(cta) and size y = F*Math.sin(cta),
When you set the above property to x,y : you tell EJS (program) x,y were determined by F and cta only.
So it can not be dragged.

move the above code to another function
Code:
function changeXY(){
x = F*Math.cos(cta);
y = F*Math.sin(cta);
}
and add changeXY() to action property when F's or cta's control property.

Computer only do what you tell it to do. It will not do more and it will not do less, either.
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #2 on: March 02, 2009, 11:48:48 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE

i learn about functions and its usefulness. will test it out asap. Thanks Prof. !!!
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #3 on: March 02, 2009, 10:00:14 pm »

This is awesome!

i added custom

Code:
public void drag(){
xp=x+Math.sqrt(dx2*dx2+dy2*dy2)*Math.cos(Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))*Math.cos(Math.atan2(dy1,dx1)); // xp = x + component cta1
yp=y+Math.sqrt(dx2*dx2+dy2*dy2)*Math.cos(Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))*Math.sin(Math.atan2(dy1,dx1)); //
R = Math.sqrt(dx2*dx2+dy2*dy2); // need this to force the value in the slider to show correctly
}

add to graphic line vectorarrowblack on drag "drag()"


and

Code:
public void changeXY() {
dx2 = R*Math.cos(cta2); // this allows the changing in R and cta2 to be fed back to dx2 and dy2
dy2 = R*Math.sin(cta2);
}
in the slider that control R add to drag "changeXY()"


i continue to have in fixed relations:

Code:
xp=x+Math.sqrt(dx2*dx2+dy2*dy2)*Math.cos(Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))*Math.cos(Math.atan2(dy1,dx1)); // xp = x + component cta1
yp=y+Math.sqrt(dx2*dx2+dy2*dy2)*Math.cos(Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))*Math.sin(Math.atan2(dy1,dx1)); //

i debugged it that i must have it here still or else  the components will show wrongly when i drag the coordinate (x,y) beginning of the vector of length dx2 and dy2 to move the origin.

It is very cool because you give enough tips, i know enough to debug and learn on my own.

you are simply awesome! Grin


*** There are 1 more attached files. You need to login to acces it!
« Last Edit: March 02, 2009, 10:57:17 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #4 on: March 02, 2009, 10:22:45 pm »

Great! you can solve it by yourself.

I believe you also enjoy it when you find out the solution by yourself.  Cheesy
Logged
Pages: [1]   Go Up
  Print  
Teaching without words. ...Lao Tzu (570-490 BC)
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
is it possible to make applet make a sound when i condition is met?
Questions related to EJS
lookang 8 10444 Last post December 22, 2008, 12:10:01 pm
by lookang
How to make for Trail to connected true for angle 0 to 360 but not jump 360-0?
Questions related to EJS
lookang 1 4192 Last post December 11, 2009, 04:07:04 pm
by Fu-Kwun Hwang
how do make Ejs applet run forever unless the pause or reset
Questions related to EJS
lookang 3 4952 Last post June 21, 2010, 07:52:30 pm
by Fu-Kwun Hwang
how to make the angle always acute between two lines?
Questions related to EJS
lookang 2 3407 Last post June 29, 2010, 11:06:13 pm
by Fu-Kwun Hwang
How make applet run one time only/board:23-100-
Question related to Physics or physics related simulation
ahmedibrahim 4 4502 Last post July 17, 2010, 12:35:45 am
by ahmedelshfie
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.06 seconds with 23 queries.since 2011/06/15