NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/  November 21, 2019, 06:39:12 am  Welcome, Guest. Please login or register.Did you miss your activation email? 1 Hour 1 Day 1 Week 1 Month Forever Login with username, password and session length Use resources around us effectively. ...Wisdom
 Pages:    Go Down Author Topic: how to make the angle always acute between two lines?  (Read 4090 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member      Offline

Posts: 1792 http://weelookang.blogspot.com  « 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 and px define the centre of polygon
px=x0; // for drawing angle polygon
py=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 px[ i ]=x0+d*Math.cos(c); //
py[ i ]=y0+d*Math.sin(c); //
}
xdeltatheta= px ; // x coordinate for text angle delta theta
ydeltatheta =py ; // 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!  Thx!
 *** 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

Posts: 1792 http://weelookang.blogspot.com  « 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
Hero Member      Offline

Posts: 3083   « 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:    Go Up
Use resources around us effectively. ...Wisdom
 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 12051 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 9200 March 02, 2009, 10:22:45 pm by Fu-Kwun Hwang  Brewster angle Request for physics Simulations yanksterh 1 6212 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 4883 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 21484 April 27, 2010, 07:37:26 pm by ahmedelshfie
Page created in 0.054 seconds with 22 queries. since 2011/06/15