From e315c7e0d3cbfd4bc72f3fc3ec5bc2384cd4fa80 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Tue, 7 Mar 2000 15:01:30 +0000 Subject: * D�placement de fonctions g�om�triques vers Geo. --- generic/Geo.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'generic/Geo.c') diff --git a/generic/Geo.c b/generic/Geo.c index 16cee3e..cf07dc3 100644 --- a/generic/Geo.c +++ b/generic/Geo.c @@ -498,6 +498,9 @@ ShiftLine(ZnPoint *p1, else { dy_neg = False; } + if ((dy == 0) && (dx == 0)) { + return; + } if (dy <= dx) { dy = ((dist * shift_table[(dy*128)/dx]) + 64) / 128; if (!dx_neg) { @@ -1072,6 +1075,58 @@ PointInAngle(int start_angle, ((angle_extent < 0) && ((angle_diff - 360) >= angle_extent))); } +/* + * PointPolarToCartesian -- + * Convert a point in polar coordinates (rho, theta) + * in a reference system described by angle heading + * (angles running clockwise) to a point in cartesian + * coordinates (delta_x, delta_y). + * + */ +void +PointPolarToCartesian(ZnReal heading, + int rho, + int theta, + int *delta_x, + int *delta_y) +{ + double to_angle; + + /* Compute angle in trigonometric system */ + to_angle = DegreesToRadian(theta) + heading - M_PI_2; + /* to_angle = heading - DegreesToRadian(theta);*/ + /* Compute cartesian coordinates */ + *delta_x = (int) (rho * cos(to_angle)); + *delta_y = (int) (rho * sin(to_angle)); +} + +/* + * Return a vector angle given its projections + */ +ZnReal +ProjectionToAngle(ZnDim dx, + ZnDim dy) +{ + if (dx == 0) { + if (dy < 0) { + return -M_PI_2; + } + else if (dy > 0) { + return M_PI_2; + } + else { + return 0.0; + } + } + else if (dx < 0) { + return atan((double) dy / (double) dx) - M_PI; + } + else { + return atan((double) dy / (double) dx); + } + return 0.0; +} + /* * Tell if an horizontal line intersect an axis aligned -- cgit v1.1