Author Topic: Represent a vector as horizontal and vertical components applet  (Read 21859 times)

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
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 <br> 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!!
« Last Edit: May 05, 2008, 10:35:16 am by lookang »

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Represent a vector as two perpendicular components Applet
« Reply #1 on: April 29, 2008, 03:31:28 pm »
completed :)

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Represent a vector as two perpendicular components Applet
« Reply #2 on: April 29, 2008, 03:37:35 pm »
refined completed :D

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Represent a vector as two perpendicular components Applet
« Reply #3 on: April 30, 2008, 08:36:59 am »
I modified some of the parameter in the EJS and post your beautiful applet -*-

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!

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Represent a vector as two perpendicular components Applet
« Reply #4 on: April 30, 2008, 06: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!

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Represent a vector as two perpendicular components Applet
« Reply #5 on: April 30, 2008, 09: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.

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Represent a vector as two perpendicular components Applet
« Reply #6 on: May 02, 2008, 10: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 "
" 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!



Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Represent a vector as two perpendicular components Applet
« Reply #7 on: May 02, 2008, 11: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.

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Represent a vector as two perpendicular components Applet
« Reply #8 on: May 02, 2008, 11: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
« Last Edit: May 02, 2008, 11:55:27 am by lookang »

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Represent a vector as two perpendicular components Applet
« Reply #9 on: May 05, 2008, 10: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 ?
"
« Last Edit: May 05, 2008, 11:52:04 am by lookang »

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Represent a vector as horizontal and vertical components applet
« Reply #10 on: May 05, 2008, 11: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. 

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Represent a vector as horizontal and vertical components applet
« Reply #11 on: May 05, 2008, 11: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 ?
"
« Last Edit: May 05, 2008, 02:37:17 pm by lookang »

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
final version, i hope :)

Represent a vector as two perpendicular components ( x and y direction )
« Last Edit: May 05, 2008, 03:05:23 pm by lookang »

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Represent a vector as horizontal and vertical components applet
« Reply #13 on: May 05, 2008, 07: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.

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Represent a vector as horizontal and vertical components applet
« Reply #14 on: May 05, 2008, 08: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
« Last Edit: March 05, 2009, 04:13:27 pm by lookang »