Thread: Slope to degrees

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    Slope to degrees

    Does anyone know how to compute the azimuth in degrees from the given slope. If the two components (the numerator and the denominatory or x component and y component) are known. This is what I have but I am not sure that it is correct.

    Code:
    double ComputeAzimuth(double dbY, double dbX)
    {
    	int iQuadrant = 0;
    	double slope;
    
    	slope = dbY/dbX;
    
    
    	if( dbX > 0 && dbY > 0)
    	{
    		iQuadrant = 1;
    	}
    	else if( dbX < 0 && dbY > 0)
    	{
    		iQuadrant = 2;
    	}
    	else if(  dbX < 0 && dbY < 0)
    	{
    		iQuadrant = 3;
    	}
    	else if(  dbX > 0 && dbY < 0)
    	{
    		iQuadrant = 4;
    	}
    
    	switch( iQuadrant )
    	{
    		case 1: return 90 - (atan(slope) * (180/PI));
    		case 2: return 270 - (atan(slope) * (180/PI));
    		case 3: return 270 - (atan(slope) * (180/PI));
    		case 4: return 90 - (atan(slope) * (180/PI));
    	}
    
    	return 0.0;
    }
    zMan

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    correction

    By the way vertical and horizontal azimuths such as 0, 90, 180, 270 are treated as special cases so they don't need to be computed through this function.
    zMan

  3. #3
    Registered User whistlenm1's Avatar
    Join Date
    Jan 2002
    Posts
    124
    if I understand your question properly, you wont to know how to calculate the inclination from the x axis of function.

    m == slope
    deg == Degree

    so

    inverse tan m = deg
    tan deg = m

    convert as need be

    Hope this helps
    Man's mind once streched by a new idea, never regains its original dimensions
    - Oliver Wendell Holmes

    In other words, if you teach your cat to bark (output) and eat dog food (input) that doesn't make him a dog. It would have to chase cars, chew bones, and have puppies before I'd call it Rover ;-)
    - WaltP

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    143
    My understanding (different from wistlenm1) is that you want to calculate the bearing of a point {dbX, dbY} from the origin taking the positive y-axis as reference 0 degrees and measuring clockwise (like a compass bearing). If I am right in my understanding, then I reckon your code will give you the answer you want...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 09-27-2008, 07:32 PM
  2. Convert DegMinSec to Decimal Degrees
    By JacquesLeJock in forum C Programming
    Replies: 3
    Last Post: 11-21-2007, 11:59 PM
  3. Temperature conversion...
    By Onslaught in forum C Programming
    Replies: 3
    Last Post: 10-21-2005, 01:15 PM
  4. sin() and cos() that use degrees
    By dwks in forum C Programming
    Replies: 3
    Last Post: 05-14-2005, 04:29 PM
  5. Is this right
    By Granger9 in forum C Programming
    Replies: 6
    Last Post: 08-14-2002, 02:21 AM