ios - Get area of intersecting line (CGPoints) -


i have array of cgpoints , find points, build shape. please see attached image: enter image description here

the red circles mark points have.

how can area question mark found?

thanks.

you going have start first line segment , check intersections. if first 2 line segments intersect same line , shape line, ignore case. continue down line segments once find segment pair intersect have shape.

check line segment 2 against line segment 1. check line segment 3 against line segment 2, against line segment 1. check 4 against 3, 2, 1, etc... if find line segment 7 intersects line segment 3, delete first point of line segment 3 , se intersection point found. delete last point of line segment 7 , set intersection point found. there have shape.

here example method find intersection of 2 line segments (written in c#, it's straight math should easy convert language like). taken here:

// determines if lines ab , cd intersect. static bool linesintersect(pointf a, pointf b, pointf c, pointf d) {     pointf cmp = new pointf(c.x - a.x, c.y - a.y);     pointf r = new pointf(b.x - a.x, b.y - a.y);     pointf s = new pointf(d.x - c.x, d.y - c.y);      float cmpxr = cmp.x * r.y - cmp.y * r.x;     float cmpxs = cmp.x * s.y - cmp.y * s.x;     float rxs = r.x * s.y - r.y * s.x;      if (cmpxr == 0f)     {         // lines collinear, , intersect if have overlap          return ((c.x - a.x < 0f) != (c.x - b.x < 0f))             || ((c.y - a.y < 0f) != (c.y - b.y < 0f));     }      if (rxs == 0f)         return false; // lines parallel.      float rxsr = 1f / rxs;     float t = cmpxs * rxsr;     float u = cmpxr * rxsr;      return (t >= 0f) && (t <= 1f) && (u >= 0f) && (u <= 1f); } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -