The simplest / most effective way to check if a square is inside a triangle

I am just wondering if there is a simple / effective way to check if the square is inside the triangle. or at least one corner gets inward or partially overlaps. for example, given the figure below, I should be able to say that 3 squares fall inside. those. square 1, obviously inside, one corner of square 2 inside and 3 overlapping. example figure

+5
source share
6 answers

I am checking out this good tutorial . It explains how to check if a point is inside a triangle using various methods. It looks like it will help when there is a square corner inside.

Barycentric, Matlab:

function d = isinside(p,a,b,c)

    % Test if a point p(x,y) is inside a triangle
    % with vertices a(x,y), b(x,y) and c(x,y)

    v0 = c - a;
    v1 = b - a;
    v2 = p - a;

    A = [dot(v0,v0) dot(v1,v0);dot(v0,v1) dot(v1,v1)];
    b = [dot(v2,v0); dot(v2,v1)];

    x  = A\b;

    % Check if point is in triangle
    if (x(1) > 0) && (x(2) > 0) && (sum(x) < 1)
        d = true;
    else
        d = false;
    end

, , , . , .

, , , .

+2

: A- > B, B- > C C- > A

. - - ( 12). - ( ), .

, . , , ... , .

+4

. , , . , .

1) 4 .

2) , / "". .

3) "" , .

4) , , . , , . , 0 .

5) , . , .

+1

, .

enter image description here

0-1 ( ); 0-1, ; . .

+1

, , , , .. , . , . . , , . , - .

0

Since you asked about Matlab because other answers explain a direct approach, I mentioned some available solutions. You can take a look at polyxpoly (if you have a display toolbar). It can handle more general cases. Otherwise, there are many contributions to file sharing, see, for example, Curve Intersect 2 . Polygon_Intersection , on the other hand, returns overlapping areas, not just intersection points.

0
source

All Articles