Click here to Skip to main content
15,894,343 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
QuestionRe: Polygon filling, and TTF mess Pin
Randor 5-Jul-21 4:23
professional Randor 5-Jul-21 4:23 
AnswerRe: Polygon filling, and TTF mess Pin
honey the codewitch5-Jul-21 4:27
mvahoney the codewitch5-Jul-21 4:27 
AnswerRe: Polygon filling, and TTF mess Pin
honey the codewitch5-Jul-21 4:30
mvahoney the codewitch5-Jul-21 4:30 
PraiseRe: Polygon filling, and TTF mess Pin
Randor 5-Jul-21 4:51
professional Randor 5-Jul-21 4:51 
GeneralRe: Polygon filling, and TTF mess Pin
honey the codewitch5-Jul-21 4:53
mvahoney the codewitch5-Jul-21 4:53 
GeneralRe: Polygon filling, and TTF mess Pin
honey the codewitch5-Jul-21 4:58
mvahoney the codewitch5-Jul-21 4:58 
AnswerRe: Polygon filling, and TTF mess Pin
Randor 5-Jul-21 7:18
professional Randor 5-Jul-21 7:18 
GeneralRe: Polygon filling, and TTF mess Pin
honey the codewitch5-Jul-21 9:09
mvahoney the codewitch5-Jul-21 9:09 
I found this:
Point in polygon - Wikiwand[^]

Which led me here: Geometry Algorithms TOC[^]

Which led me to some code, but I think i'm looking at the wrong routine because when I implemented theirs I get the same dodgy result I do when I use .NET's FillPolygon() or when I use my own even-odd method in C++ (picture of the result in the original post)

C++
// wn_PnPoly(): winding number test for a point in a polygon
//      Input:   P = a point,
//               V[] = vertex points of a polygon V[n+1] with V[n]=V[0]
//      Return:  wn = the winding number (=0 only when P is outside)
int
wn_PnPoly( Point P, Point* V, int n )
{
    int    wn = 0;    // the  winding number counter

    // loop through all edges of the polygon
    for (int i=0; i<n; i++) {   // edge from V[i] to  V[i+1]
        if (V[i].y <= P.y) {          // start y <= P.y
            if (V[i+1].y  > P.y)      // an upward crossing
                 if (isLeft( V[i], V[i+1], P) > 0)  // P left of  edge
                     ++wn;            // have  a valid up intersect
        }
        else {                        // start y > P.y (no test needed)
            if (V[i+1].y  <= P.y)     // a downward crossing
                 if (isLeft( V[i], V[i+1], P) < 0)  // P right of  edge
                     --wn;            // have  a valid down intersect
        }
    }
    return wn;
}


That's from the book, but I reimplemented it in C# with my C# version of my TTF renderer, so I'm still digging, but I've maybe made some progress..

ETA: I should note while you may not be familiar with this variant of the winding algorithm depending on the last time you had to do this, in the first link it's covered here:

Quote:
There is a significant speed-up (known since 2001) of the winding number algorithm. It uses signed crossings, based on whether each crossing is left-to-right or right-to-left. Details and C++ code are given at the link in the following annotation .[6] Angles are not used, and no trigonometry is involved. The code is as fast as the simple boundary crossing algorithm. Further, it gives the correct answer for nonsimple polygons, whereas the boundary crossing algorithm fails in this case.

Real programmers use butterflies


modified 5-Jul-21 15:17pm.

GeneralRe: Polygon filling, and TTF mess Pin
Randor 5-Jul-21 11:28
professional Randor 5-Jul-21 11:28 
GeneralRe: Polygon filling, and TTF mess Pin
honey the codewitch5-Jul-21 12:19
mvahoney the codewitch5-Jul-21 12:19 
GeneralRe: Polygon filling, and TTF mess Pin
honey the codewitch5-Jul-21 12:29
mvahoney the codewitch5-Jul-21 12:29 
GeneralRe: Polygon filling, and TTF mess Pin
Randor 6-Jul-21 4:28
professional Randor 6-Jul-21 4:28 
GeneralRe: Polygon filling, and TTF mess Pin
honey the codewitch6-Jul-21 4:36
mvahoney the codewitch6-Jul-21 4:36 
GeneralRe: Polygon filling, and TTF mess Pin
Super Lloyd5-Jul-21 5:00
Super Lloyd5-Jul-21 5:00 
GeneralRe: Polygon filling, and TTF mess Pin
honey the codewitch5-Jul-21 12:53
mvahoney the codewitch5-Jul-21 12:53 
QuestionMessage Closed Pin
5-Jul-21 2:19
Marketing Media Hub5-Jul-21 2:19 
AnswerRe: Is there a way to add strings to a list without the quotation marks in C++? Pin
Maximilien5-Jul-21 2:26
Maximilien5-Jul-21 2:26 
GeneralRe: Is there a way to add strings to a list without the quotation marks in C++? Pin
OriginalGriff5-Jul-21 2:28
mveOriginalGriff5-Jul-21 2:28 
AnswerRe: Is there a way to add strings to a list without the quotation marks in C++? Pin
OriginalGriff5-Jul-21 2:27
mveOriginalGriff5-Jul-21 2:27 
AnswerRe: Is there a way to add strings to a list without the quotation marks in C++? Pin
harold aptroot5-Jul-21 2:34
harold aptroot5-Jul-21 2:34 
GeneralRe: Is there a way to add strings to a list without the quotation marks in C++? Pin
KarstenK5-Jul-21 4:14
mveKarstenK5-Jul-21 4:14 
QuestionMessage Closed Pin
5-Jul-21 2:24
Marketing Media Hub5-Jul-21 2:24 
AnswerRe: Dont work, it´s something whit the loops? Pin
Maximilien5-Jul-21 2:25
Maximilien5-Jul-21 2:25 
AnswerRe: Dont work, it´s something whit the loops? Pin
OriginalGriff5-Jul-21 2:26
mveOriginalGriff5-Jul-21 2:26 
AnswerRe: Dont work, it´s something whit the loops? Pin
honey the codewitch5-Jul-21 2:26
mvahoney the codewitch5-Jul-21 2:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.