Skip to content

line_in_rectangle_rotated_nearest

Vašek edited this page Feb 10, 2019 · 2 revisions

line_in_rectangle_rotated_nearest

Returns the nearest intersection point of the given line and the given rectangle

Syntax:

line_in_rectangle_rotated_nearest(p1, p2, r)
Argument Description
Vector2 p1 The first point of the given line
Vector2 p2 The other point of the given line
RotatedRectangle r The given rectangle

Returns: Vector2?

Description:

If a given line intersects a given rectangle, the function returns the nearest intersection point. Otherwise, the function returns null.

Example:

Vector2 p1 = new Vector2(8, 8);
Vector2 p2 = new Vector2(8, 24);
Vector2 p3 = new Vector2(24, 24);
Vector2 p4 = new Vector2(24, 8);
RotatedRectangle r = new RotatedRectangle(p1, p2, p3, p4);

Vector2? pos = line_in_rectangle_rotated_nearest(new Vector2(0, 0), new Vector2(64, 64), r);

if (pos.HasValue)
{
    Vector2 point = pos.Value;
}

This function will set point to 8, 8.

Back to Raycasting

Clone this wiki locally