NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
October 24, 2017, 07:33:36 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  
Wisdom is to form a good attitude and a healthy lifestyle. ...Wisdom
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 make the angle always acute between two lines?  (Read 3312 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: June 29, 2010, 02:52:02 pm » posted from:Singapore,,Singapore

how to make the angle always acute angle (0 < 90 degree) between two lines defined between (x,y) and (xs,ys)?

i have been able to make a polygon to be drawn be using this method

// dcangle is to spilt the angle between cta and ctas into parts
dcangle = (Math.atan2(y,x)-Math.atan2(ys,xs))/(n-2);// modify to draw from black line sing dx and dy as inputs
// px[0] and px[0] define the centre of polygon
px[0]=x0; // for drawing angle polygon
py[0]=y0; //
// if statement to draw polygon angle
for(int i = 1;i// c=Math.atan2(y,x)-(i-1)*dcangle; // modify to work drawing from black line
  c=Math.atan2(y,x)-(i-1)*dcangle;
// if(c>pi)c-=2*pi; // to overcome pi to -pi problem ?? didnt work for me Grin
  px[ i ]=x0+d*Math.cos(c); //
  py[ i ]=y0+d*Math.sin(c); //
}
xdeltatheta= px[17] ; // x coordinate for text angle delta theta
ydeltatheta =py[17] ; // y coordinate for text angle delta theta

this method is remixed from http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=634.0 so i learn from changing it.

is there any elegant way to do this? how would an expert do this?

i want to make delta theta always acute angle 0 < 90 degree
the 'problem' occurs when in 2 situations:
1 (xs,ys) is in the 2nd quadrant (top right corner) and (x,y) is in 3rd quadrant (bottom left corner)
2 (x,y) is in the 2nd quadrant (top right corner) and (xs,ys) is in 3rd quadrant (bottom left corner)

the problem is captured here

usually is work well thanks to all your source codes i was able to refer to them! Smiley

Thx!


* wrongdelattheta.png (9.98 KB, 513x529 - viewed 280 times.)

* wrongdelatthetacorrectmostofthetime.png (11.17 KB, 505x534 - viewed 284 times.)

*** There are 1 more attached files. You need to login to acces it!
« Last Edit: June 29, 2010, 03:02:25 pm by lookang » Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #1 on: June 29, 2010, 09:46:00 pm » posted from:Singapore,,Singapore

don't to worry! i did it!

done!

tn = Math.atan2(y,x);
tns =Math.atan2(ys,xs);

if (Math.abs(tn-tns)>pi) // test whether tn = +3.1 and tns = -2.9 , pi is an arbitrary large angle that i thought was convience
{
dcangle = (Math.atan2(y,x)-2*pi-Math.atan2(ys,xs))/(n-2);
}
else
{
dcangle = (Math.atan2(y,x)-Math.atan2(ys,xs))/(n-2);// same as before
}
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #2 on: June 29, 2010, 11:06:13 pm » posted from:Taipei,T\'ai-pei,Taiwan

I will define two variables:
ca=Math.atan2(y,x);
cb=Math.atan2(ys,xs);

And replace all the Math.atan2(y,x) with ca, and Math.atan2(ys,xs) with cb.
So that the code do not to call Math.atan2 a lot of times (especially inside loops).

Try to reduce calculation inside any loop. It will make the program more efficient.
Logged
Pages: [1]   Go Up
  Print  
Wisdom is to form a good attitude and a healthy lifestyle. ...Wisdom
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
is it possible to make applet make a sound when i condition is met?
Questions related to EJS
lookang 8 10203 Last post December 22, 2008, 12:10:01 pm
by lookang
How to make an applet that is controlled by F (length) and angle (cta)
Questions related to EJS
lookang 4 7902 Last post March 02, 2009, 10:22:45 pm
by Fu-Kwun Hwang
Brewster angle
Request for physics Simulations
yanksterh 1 5718 Last post May 16, 2009, 09:44:02 am
by Fu-Kwun Hwang
How to make for Trail to connected true for angle 0 to 360 but not jump 360-0?
Questions related to EJS
lookang 1 4121 Last post December 11, 2009, 04:07:04 pm
by Fu-Kwun Hwang
Pendulum (Why the angle need to be less than 5 degree --- is it necessary?)
dynamics
ahmedelshfie 0 15037 Last post April 27, 2010, 07:37:26 pm
by ahmedelshfie
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.068 seconds with 22 queries.since 2011/06/15