AngleFromSlope
Fixed theSlope ; ratio of dh/dv returns angle in degrees (-180 to 180)
Given the slope of a line (the dh/dv or the horizontal change divided by the
calculates the angle of that line. The calculation is approximate to the nearest
degree.
theSlope a 4-byte Fixed value; the dh/dv ratio of points on a line. Returns: a signed short integer representing the angle most closely matching the specified slope ratio. Positive values are clockwise from vertical
and negative values are counterclockwise.
Notes: The returned angle is expressed in circular degrees, going clockwise with
12 o'clock at 0°, 3 o'clock at 90°, etc. Negative values are
counterclockwise from straight up; e.g., 9 o'clock is -90°.
The following example calculates the slope of a line represented by two
Example
#include <ToolUtils.h>
#define INT2FIX(i) ((long) i << 16 )/* short to Fixed conversion macro */ short theAngle, dh, dv;
dh = startPt.h - endPt.h; /* calculate the deltas */
dv = startPt.v - endPt.v; theSlope = FixRatio( INT2FIX(dh), INT2FIX(dv) ); /* slope=dh/dv */