NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => misc => Topic started by: lookang on April 29, 2008, 01:45:51 pm



Title: Represent a vector as horizontal and vertical components applet
Post by: lookang on April 29, 2008, 01:45:51 pm
hihi prof,

how do i make the text strings intelligently display in the applet on the next line.

I previously used a method by spacing but when the display screen auto scale, my spacing is not shown with optimum spacing.

is there a code like
 or next line to make the string automatically go to next line on the applet screen
.

attached is my xml


well i relooked at some of the conversation we had,

i will play with the
You can set those string to the same (x,y) and set different alignment property for those strings (lower right, upper right,lower left, upper left;  4 strings maximum) .
http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=533.msg1802#msg1802

I will be using the method you explained in quotes until i find a better way !!

thanks!!


Title: Re: Represent a vector as two perpendicular components Applet
Post by: lookang on April 29, 2008, 02:31:28 pm
completed :)


Title: Re: Represent a vector as two perpendicular components Applet
Post by: lookang on April 29, 2008, 02:37:35 pm
refined completed :D


Title: Re: Represent a vector as two perpendicular components Applet
Post by: Fu-Kwun Hwang on April 30, 2008, 07:36:59 am
I modified some of the parameter in the EJS and post your beautiful applet -*-


Title: Re: Represent a vector as two perpendicular components Applet
Post by: lookang on April 30, 2008, 05:03:41 pm
Hi prof

i want to make the applet always show equal size for x and y axes for the reason that circle will look like circle instead of an eclipse.


any tips how to do it??

i try changing the PlottingFrame Size to a variable name "size",

i try making a checkbox to action a function say called showsum()  {actually i instead to equalaxes} ;D

and i added a custom function

but it didn't work.


chance to tip me on the easiest way to mqke a checkbox that when checked will make the PlottingFrame Size equal ?

thanks!


Title: Re: Represent a vector as two perpendicular components Applet
Post by: Fu-Kwun Hwang on April 30, 2008, 08:30:18 pm
The x/y axes was determined from properties of DrawingPanel. The default setting was auto-scale in both dimension. You can adjust xmin,xmax,ymin,ymax values to  achieve whatever you want. As long as the x/y dimension of DrawingPanel and ratio of (xmax-xmin)/(ymax-ymin) is the same , you will get equal size for x and y axes.


Title: Re: Represent a vector as two perpendicular components Applet
Post by: lookang on May 02, 2008, 09:59:32 am
thanks for your tip and guidance.

managed to do something already.


problem statement on http://forum.java.sun.com/thread.jspa?threadID=5211941&messageID=9855498

trying to write next line.

i tried the method "\n" to go to the next line but it didn't work.

any idea why ?

quote 1: result in /n in the text
s_vxformula = "{A_x}= "+"A*cos("+thetasymbol+"{^o})"+"/n"+" = "+double2String(A,100.)+"*cos("+double2String(alpha,10.)+"{^o})";







thanks!




Title: Re: Represent a vector as two perpendicular components Applet
Post by: Fu-Kwun Hwang on May 02, 2008, 10:25:09 am
The method you found: write is display text string in a textarea.
However, in the drawingPanel, what you want to do is DRAW a STRING on the drawing Panel.
To draw, you can draw at any position. For textarea, it was first divided as line, and text can only displayed on those line. So next line make sense. However, there is no next line in the drawing Panel.
That is the reason why it was not working for your case.


Title: Re: Represent a vector as two perpendicular components Applet
Post by: lookang on May 02, 2008, 10:36:30 am
ok thanks

seems like have to use the +h method to display the next line ......

it is the update the xml file again

cheers prof  ;D


New title
Represent a vector (A) as horizontal (A_{x}) and vertical A_{y} components


Title: Re: Represent a vector as two perpendicular components Applet
Post by: lookang on May 05, 2008, 09:32:43 am
hi prof,

i have been trying to make the angle drawn as a dynamic pie for the angle instead of a hollow one, how do i filled the inside with a color ?

i read the reference but still i cant understand the logic of the polygon.

luckily i found

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

will study ur codes  ;D


but it seems a bit harder than i thought,

but i did it !!!


under constraints:

what does 2 lines do ? i completely cannot follow

"
 c=cta2-(i-1)*dc; //  c = end of angle segment - (i-1)*a small segment ?
  if(c<-pi)c+=2*pi; // if c less than - Math.PI then c add one until 2*PI ?
"


Title: Re: Represent a vector as horizontal and vertical components applet
Post by: Fu-Kwun Hwang on May 05, 2008, 10:47:48 am
For 2-D polygon element in the EJS, you need to provide x[n],y[n] arrays to represent the X,Y coordinate for n points.

If the polygon is not closed (you can change the property), then ejs will draw all the points and draw lines between i and i+1 points except the last one.
If the polygon is closed, then it will draw another line connect the last point to the first one. When it is a closed polygon, you can set color to fill the inside of the polygon. 


Title: Re: Represent a vector as horizontal and vertical components applet
Post by: lookang on May 05, 2008, 10:54:21 am
i managed to make ur codes work in my applet :)

check the post above :)

BTW:
what does 2 lines do ? i completely cannot follow

"
 c=cta2-(i-1)*dc; //  c = end of angle segment - (i-1)*a small segment ?
  if(c<-pi)c+=2*pi; // if c less than - Math.PI then c add one until 2*PI ?
"


Title: Represent a vector as two perpendicular components ( x and y direction ) applet
Post by: lookang on May 05, 2008, 01:34:31 pm
final version, i hope :)

Represent a vector as two perpendicular components ( x and y direction )


Title: Re: Represent a vector as horizontal and vertical components applet
Post by: Fu-Kwun Hwang on May 05, 2008, 06:57:30 pm
i managed to make ur codes work in my applet :)

check the post above :)

BTW:
what does 2 lines do ? i completely cannot follow

"
 c=cta2-(i-1)*dc; //  c = end of angle segment - (i-1)*a small segment ?
  if(c<-pi)c+=2*pi; // if c less than - Math.PI then c add one until 2*PI ?
"

The purpose of the above code is to make sure angle c would not be less than -pi;
If it is less than -pi, add the angle with 2*pi.
I think the purpose is to have correct calculated components.


Title: Re: Represent a vector as horizontal and vertical components applet
Post by: lookang on May 05, 2008, 07:13:12 pm
oic.... cool...never thought of that....thanks!

the applet now here http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=681.0