aboutsummaryrefslogtreecommitdiff
path: root/generic/Geo.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/Geo.c')
-rw-r--r--generic/Geo.c55
1 files changed, 55 insertions, 0 deletions
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