T
T
TimeCoder2016-05-13 00:26:01
Algorithms
TimeCoder, 2016-05-13 00:26:01

What is the formula for the intersection of line segments on a chessboard?

Hello,
on the topic of intersections of segments and the projection of a point onto a line - everything is already ready, there are many examples and formulas. How can formulas be simplified if the geometric space is a chessboard? Those.
1. The coordinates of a point, or the beginning and end of a segment, are integer.
2. Segments can be arranged in three directions: vertically, horizontally, diagonally.
Those. in this "world" there are no other angles than 0, 45 and 90.
Task:
1. Find the point of intersection of two segments.
2. Find the intersection point of the segment and the line drawn (before the first intersection) from a certain point in one of 8 possible directions.
Of course, I don’t ask for a ready-made code, just where to dig to calculate it quickly (you need a high calculation speed).
UPD1: even simpler, there is a point with two coordinates, and a direction from it (one of 8 possible, according to the cardinal points). Somewhere on the same plane there is a segment given by the coordinates of the beginning and end. If, moving from a point, we eventually cross the segment, then only at an angle of 90 or 45 degrees. It is necessary to find the intersection point by naming the coordinates of the point, the direction of movement, and the coordinates of the segment.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question