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

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: lookang on August 14, 2007, 02:07:59 pm



Title: how to draw a fraction of a circle for angle showing in plotting panel
Post by: lookang on August 14, 2007, 02:07:59 pm
hihi,

i looked through some of the xml examples and got some idea on usage of 2D drawables - polygon.

An array with 3 coordinates defined the vertices of a triangle.

Quoted from friction.xml

Model variables

PX {xmin,xmin,xmax} double 3

PY {ymin,yh,ymin}  double 3

View Polygon
points 3
X   PX
Y   PY
Unquote:

My question is how to do a partial circle easily?

my initial idea is 7 points  using

{origin, r.Math.cos(alpha/6) , r.Math.cos(2*alpha/6), r.Math.cos(3*alpha/6), r.Math.cos(4*alpha/6), r.Math.cos(5*alpha/6), r.Math.cos(6*alpha/6) }

{origin, r.Math.sin(alpha/6) , r.Math.sin(2*alpha/6), r.Math.sin(3*alpha/6), r.Math.sin(4*alpha/6), r.Math.sin(5*alpha/6), r.Math.sin(6*alpha/6) }

is this easiest way ?

Thanks ;D


Title: Re: how to draw a fraction of a circle for angle showing in plotting panel
Post by: Fu-Kwun Hwang on August 14, 2007, 04:22:51 pm
Polygon is a GUI element for drawing any shape in drawingPanel/PlottingPanel/DrawingPanel3D.

Basically, you define number of points, and all the coordinates for x[n],y[n](,z[n] for 3D).
And Ejs will draw connected lines between those points.
For half of a circle, I will do the following
int np=20;
double dc=Math.PInp;
double x[n],y[n];
double R=10,c;// radius and angle
And, initialize it with the following code:
for(int i=0;i c=i*dc;
 x=R*Math.cos(c);
 y=R*Math.sin(c);
}
And assign x,y to X,Y propertie of polygon
And you will get a half circle drawing.

There is another GUI elements called AnalyticCurve.
You can set up properties as following
Points: 20
Minimum: 0
Maximun: Math.PI
Variable: c
X(): R*Math.cos(c)
Y(): R*Math.sin(c)

If you set [Java Syntax] to false (default is true)
You can set
X(): R*cos(c)
Y(): R*sin(c)

And you will get the same result. (You need to define R first)
Basically, EJS will use the above information to set up polygon elements for you.

You can find out the examples for most of the GUI elements under the _example directory.

I have an online course for EJS workshop (http://enjoy.phy.ntnu.edu.tw/course/view.php?id=246) (However, it is in Chinese) at another web site.
You will find step by step tutorial in flash SWF format to show you how to create simulations with EJS.
It also contains all the related information for basic java programming.
You need to register for the web site to view all the contents.


Title: Re: how to draw a fraction of a circle for angle showing in plotting panel
Post by: lookang on August 14, 2007, 05:06:37 pm
http://enjoy.phy.ntnu.edu.tw/mod/resource/view.php?id=8505

interesting swf.
http://enjoy.phy.ntnu.edu.tw/mod/resource/view.php?id=8505 (http://enjoy.phy.ntnu.edu.tw/mod/resource/view.php?id=8505)
i registered  :D


i will try analytic curve later, looks more easy for circle.

thanks



Title: Re: how to draw a fraction of a circle for angle showing in plotting panel
Post by: Fu-Kwun Hwang on August 14, 2007, 07:36:15 pm
You can use AnalyticCurve for any curve you want as long as you know how to express x,y in turn of mathematic equations.


Title: Re: how to draw a fraction of a circle for angle showing in plotting panel
Post by: lookang on August 14, 2007, 10:50:01 pm
using analytic curve is good.

but it is possible to

1. close the arc with 2 lines(radius lines at alpha 0 and at alpha)

2. select fill color some how?



10*Math.cos(alpha*Math.PI/180)
10*Math.sin(alpha*Math.PI/180)

or perhaps i should use the polygon with a built in fill color option  ;D

thanks


Title: Re: how to draw a fraction of a circle for angle showing in plotting panel
Post by: Fu-Kwun Hwang on August 14, 2007, 11:05:30 pm
For simple closed curve(circle). Yes. please use polygon element.

For ths above case (draw area between two vertical lines ,for projectile motion etc...) :
Draw those curves with Analytic Curve, and fill the region you want with polygon.
You can draw several curves with one analyticCurve element.
Define an array as values for parameter, and define the name used in your equations.
Please check out Blackbody radiation curves for different temperatures (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=427.0). It was plotted with one AnalyticCurve element.




Title: Re: how to draw a fraction of a circle for angle showing in plotting panel
Post by: lookang on August 15, 2007, 12:46:28 am
i was unable to do polygon  :-\

still don't quite understand the logic.

nevermind i try some other time.

i stick to analytic curve  :D


Title: Re: how to draw a fraction of a circle for angle showing in plotting panel
Post by: Fu-Kwun Hwang on August 15, 2007, 08:55:15 am
i was unable to do polygon  :-\

still don't quite understand the logic.

nevermind i try some other time.

i stick to analytic curve  :D
The required properties for polygon are:
1. number of connected point (integer)
2. x,y coordinates for those n points (so two double array are required).
For drawing half of a circle (from 0-Math.PI).
You can define
n: 20 (integer) // set initial value to 20
R: 10. (double) // radius for circle
x[n]: (double) // it is not easy to set 20 values at the variable page in model panel, so we will do it in initialize page (or custom page).
y[n]: (double)
where x[n],y[n] are double array.

np=20;
double dc=Math.PI/n ,c; // define temperate variables:  dc,c
for(int i=0;i< n;i++){
 c=i*dc;
 x=R*Math.cos(c);
 y=R*Math.sin(c);
}
In View page:
Assign x,y to X,Y properties for polygon, n to number of points.
And you will get a half circle drawing.
You can play with other properties to see what will be changed.
(You are a quick learner, you will find out by yourself).