473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Angle in degree

1
I found the angle in degree with positive sign .
but angle is not satisfying the condition .
It should satisfy . It should print out cout as "right"

Does i make any mistake in calculating an angle or in conditon

please guide me thanks

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. #include <math.h>
  5.  
  6. #define PI 3.14159265
  7.  
  8. #define yes  1
  9. #define yes_no TRUE
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.  
  15.       //two points with x and y coordinates 
  16.     int x1 = 200 , y1 = 150, x2 =250, y2 =170;
  17.  
  18.     //distance b/w them
  19.     int X = x1 - x2;
  20.     int Y = y1 - y2;
  21.  
  22.     int x = pow((double)X,2);
  23.     int y = pow((double)Y,2);
  24.  
  25.     int d = abs( sqrt( (double)x + (double)y ) ); 
  26.  
  27.     int angleInRadian = atan2((double)Y,(double)X); //angle in radian
  28.  
  29.     int angleInDegree = abs(angleInRadian * 180 / PI);
  30.  
  31.     cout<<"Radian Angle between two Points .."<< angleInRadian <<endl;
  32.     cout<<"Degree Angle between two Points .."<< abs(angleInDegree) <<endl;
  33.  
  34.     if( angleInDegree >270 && angleInDegree < 90)
  35.     {
  36.         cout<<"move to right side.."<<endl;
  37.     }
  38.     else if ( angleInDegree <269 && angleInDegree > 91 )
  39.     {
  40.         cout<<"move to left side.."<<endl;
  41.     }
  42.     return 0;
  43. }
Aug 11 '11 #1
2 3130
whodgson
542 512MB
pow() takes double arguments and returns a double.
It is defined in <cmath>. i.e.x,y and 2 should be doubles.
Also please place your
Expand|Select|Wrap|Line Numbers
  1. code
in code tags
Aug 14 '11 #2
whodgson
542 512MB
Do these mods give you what you are looking for?
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. #include <cmath>
  5.  
  6. #define PI 3.14159265
  7.  
  8. #define yes 1
  9. #define yes_no TRUE
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.  
  15. //two points with x and y coordinates 
  16. double x1 = 200.0 , y1 = 150.0, x2 =250.0, y2 =170.0;
  17.  
  18. //distance b/w them
  19. double X = x1 - x2;
  20. double Y = y1 - y2;
  21.  
  22. double x = pow((double)X,2.0);
  23. double y = pow((double)Y,2.0);
  24.  
  25. double d = abs( sqrt( (double)x + (double)y ) ); 
  26.  
  27. double angleInRadian = atan2((double)Y,(double)X); //angle in radian
  28.  
  29. double angleInDegree = abs(angleInRadian * 180 / PI);
  30.  
  31. cout<<"\nRadian Angle between two Points .."<< angleInRadian <<endl;
  32. cout<<"Degree Angle between two Points .."<< abs(angleInDegree) <<endl;
  33.  
  34. if( angleInDegree >270 && angleInDegree < 90)
  35. {
  36. cout<<"move to right side.."<<endl;
  37. }
  38. else if ( angleInDegree <269 && angleInDegree > 91 )
  39. {
  40. cout<<"move to left side.."<<endl;
  41. }
  42. cout<<"press any key...\n";
  43. cin.get();
  44. return 0;
  45. }
  46. /*
  47. Radian Angle between two Points ..-2.76109
  48. Degree Angle between two Points ..158.199
  49. move to left side..
  50. press any key...
  51. */
Aug 17 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Darren Grant | last post by:
Hi there, I've attempted to implement an Angle class. An Angle is a subset of an integer, where the range is [0,360). All other operations should be permitted. The code works, I think......
7
by: Bindul Bhowmik | last post by:
I am in a project and have to find out the value of cos of an angle. The user will input the value of the angle only in degrees. I am using the following expression to get the radian equivalent of...
3
by: Lasse Eskildsen | last post by:
Hi, I'm trying to measure an angle of a triangle in vb.net, but I'm not getting it right. This is my triangle (kind of): A l\ 1 \ 1 \
1
by: Ricardo Furtado | last post by:
I'm programming in vb .Net and i need to know how to determine angles. For example i have a figure like the following: | | | ------------------ | | |
15
by: cwsullivan | last post by:
Hi gang, I have a grid full of particles in my program, and I want to find an angle between two particles. I'm having trouble because it seems like the answer depends on whether or not the target...
8
by: giloosh | last post by:
how would i get the distance and angle between 2 points on the screen. For example: what is the distance between (100,50) and (250,70) what i really wanna do is see how far the current mouse...
66
by: stryfedll | last post by:
Sorry this isn't directly concerning a programming language but I wanted to reach real programmers. I am in college right now and am not really interested in investing 3 more years of my life for a...
4
by: Jem | last post by:
Hi all I have the following code which draws a vertical line on a form... Dim VertCrossHairX1 As Integer = 75 Dim VertCrossHairX2 As Integer = 75 Dim VertCrossHairY1 As Integer = 70 Dim...
3
by: Doraj | last post by:
Hello ! Here is my problem : I had some php scripts which worked well with php 4.0.5 (GD 1.6.2 according to phpinfo() ) and i put them on a new server with php 4.4.2 (and GD 2.0.28). Now,...
2
by: laredotornado | last post by:
Hi, I'm using php 4.4.4. Maybe I'm misreading the docs, but in the imagettfbbox manual (http://us2.php.net/imagettfbbox), it says that text coordinates are the same regardless of what the angle...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.