aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generic/Geo.c55
-rw-r--r--generic/Geo.h15
2 files changed, 70 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
diff --git a/generic/Geo.h b/generic/Geo.h
index 8a173b1..8403819 100644
--- a/generic/Geo.h
+++ b/generic/Geo.h
@@ -64,6 +64,10 @@
#define DegreesToRadian(angle) \
(M_PI * (double) (angle) / 180.0)
+#define RadianToDegrees(angle) \
+ (fmod((angle) * 180.0 / M_PI, 360.0))
+#define RadianToDegrees360(angle) \
+ (fmod(RadianToDegrees(angle)+360.0,360.0))
#define REAL_TO_INT(double) \
(((int) ((double) + (((double) > 0) ? 0.5 : -0.5))))
@@ -174,6 +178,17 @@ PointInAngle(int start_angle,
int angle_extent,
ZnPoint *p);
+void
+PointPolarToCartesian(ZnReal heading,
+ int rho,
+ int theta,
+ int *delta_x,
+ int *delta_y);
+
+ZnReal
+ProjectionToAngle(ZnDim dx,
+ ZnDim dy);
+
double
RectangleToPointDist(ZnBBox *bbox,
ZnPoint *p);