NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
October 18, 2017, 03:27:20 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  
Everything has its beauty but not every one sees it. ...Confucius (551-479 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 draw a fraction of a circle for angle showing in plotting panel  (Read 16238 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: August 14, 2007, 02:07:59 pm » posted from:Singapore,,Singapore

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 Grin
« Last Edit: August 14, 2007, 03:35:53 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #1 on: August 14, 2007, 04:22:51 pm » posted from:Taipei,T\'ai-pei,Taiwan

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 (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.
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #2 on: August 14, 2007, 05:06:37 pm » posted from:Singapore,,Singapore

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
i registered  Cheesy


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

thanks

Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #3 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.
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #4 on: August 14, 2007, 10:50:01 pm » posted from:Singapore,,Singapore

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  Grin

thanks
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #5 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. It was plotted with one AnalyticCurve element.


Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #6 on: August 15, 2007, 12:46:28 am » posted from:Singapore,,Singapore

i was unable to do polygon  Undecided

still don't quite understand the logic.

nevermind i try some other time.

i stick to analytic curve  Cheesy
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #7 on: August 15, 2007, 08:55:15 am »

i was unable to do polygon  Undecided

still don't quite understand the logic.

nevermind i try some other time.

i stick to analytic curve  Cheesy
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).
Logged
Pages: [1]   Go Up
  Print  
Everything has its beauty but not every one sees it. ...Confucius (551-479 BC)
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Ask : How to draw v(t) with EJS
Question related to Physics or physics related simulation
ahmedelshfie 5 5974 Last post January 05, 2010, 11:25:25 pm
by Fu-Kwun Hwang
How do I get the cursor position in a running plotting panel?
Questions related to EJS
Abyss333 3 4938 Last post October 21, 2010, 09:40:06 pm
by Abyss333
Request for animation showing electron drift velocity
Request for physics Simulations
ibex52 1 7029 Last post July 26, 2011, 09:31:12 pm
by Fu-Kwun Hwang
Physics of collision showing forces at event for 1 dimension
Questions related to EJS
lookang 1 3190 Last post March 13, 2012, 10:41:18 pm
by Fu-Kwun Hwang
Adding Fraction
misc
Fu-Kwun Hwang 0 10145 Last post October 25, 2013, 07:33:37 pm
by Fu-Kwun Hwang
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.055 seconds with 22 queries.since 2011/06/15