NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
April 05, 2020, 06:32:11 pm

Progress is impossible without change; and those who cannot change their minds cannot change anything. ..."George Bernard Shaw(1865-1950, Irish dramatist, essayist and critic, Nobel Prize for Literature 1925)"

 Pages: [1]   Go Down
 Author Topic: How to make an applet that is controlled by F (length) and angle (cta)  (Read 9334 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member

Offline

Posts: 1794

http://weelookang.blogspot.com

 « 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 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 I am struck here

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
Hero Member

Offline

Posts: 3085

 « 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

Posts: 1794

http://weelookang.blogspot.com

 « 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

Posts: 1794

http://weelookang.blogspot.com

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

This is awesome!

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!
 *** 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
Hero Member

Offline

Posts: 3085

 « 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.
 Logged
 Pages: [1]   Go Up
Progress is impossible without change; and those who cannot change their minds cannot change anything. ..."George Bernard Shaw(1865-1950, Irish dramatist, essayist and critic, Nobel Prize for Literature 1925)"