Posted by Ariel on Saturday, November 10, 2007 at 4:33pm.

So I need a function (parameters: origin x, origin y, destination x, destination y, object x1, object y1, object x2, object y2). The object in this case would be a wall with two points (x1, y1, x2, y2). The function needs to return a true/false if the wall intersects the path. As in, does it cross between the origin and destination. In other words, we have two finite lines (path of movement and wall), and I need to know if they cross.

How do I do that?

I program in basic (small basic) but I would rather if you wouldn't add code, just plain english.

Thanks in advance!

To determine whether a wall intersects the path between two points, you can use a mathematical method called line intersection. Here's a step-by-step explanation of how you can achieve this:

1. Start by calculating the slope (m) of both the path and the wall. The slope of a line is determined by the change in y divided by the change in x. Use the formula: m = (y2 - y1) / (x2 - x1).

2. Next, calculate the y-intercept (b) of both lines. The y-intercept is the value of y when x is equal to 0. Use the formula: b = y - (m * x).

3. With the slope (m) and y-intercept (b) calculated for both lines, you now have their equations in the form of y = mx + b.

4. Now, check if the two lines are parallel. If their slopes (m1 and m2) are equal, but their y-intercepts (b1 and b2) are different, then the lines are parallel and do not intersect. In this case, return false.

5. If the lines are not parallel, calculate the x-coordinate (x_intersect) at which the two lines intersect. You can do this by setting the two equations equal to each other: mx + b = mx + b. Solve for x to find the common x-coordinate.

6. After finding the x-coordinate of intersection, substitute it back into either equation to get the y-coordinate (y_intersect) of the intersection point.

7. Finally, check if the intersection point falls within the range of the two line segments. Compare the x and y values of the intersection point to the minimum and maximum x and y values of the line segments. If the intersection point's x and y values are within these ranges, then the wall intersects the path. Return true in this case. Otherwise, return false.

Note: Make sure to handle special cases such as vertical lines separately to avoid division by zero errors in the calculations.

By following these steps, you can determine if a wall intersects the path between two points without actually writing code.