polygon filling

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BSOB
    New Member
    • Jul 2006
    • 77

    polygon filling

    im gone for a long weekend so plenty of time for anyone to answer.
    if i have 4 points representing a polygon and each point is represented by an x and a y coordinate, is there an easy (or slightly less painfull) way to decide whether or not a point (a,b) lays within that polygon?

    please note that this polygon DOES NOT take the shape of a square and has NO right angles and all side lengths are somewhat random.

    the application:
    say i wanted to draw a picture on the screen. i had the computer pick 8 random numbers (within screen limits) representing 4 random points. and now i want to fill in the area created by this polygon using point(x,y),z.
    the polygon is convex in all situations. i also already know which points make up a side. for example, if there is point a, b, c, and d. I know a_b is a line, and b_c is a line, and c_d is a line and d_a is a line. i know which points are which so i can assume that point a has no relation to point c.

    um.. yah, help?
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    #2
    Hi BSOB,

    enjoy your holiday for the time being.. have a great time out there.. hope to find a solution for your question.. take care my fren.. :)

    Comment

    • BSOB
      New Member
      • Jul 2006
      • 77

      #3
      I have solved my problem with a simple few lines. If anyone is interested in my solution, post here and i will be happy to share it.

      Comment

      • Kang
        New Member
        • Sep 2006
        • 1

        #4
        Hi, I really would like to know how you manage to solve that, been looking around on the web but so far still have no clue on how to do it. Thanks in advance.

        Comment

        • ravenvort
          New Member
          • Sep 2006
          • 3

          #5
          please share the solution, for future projects.... thanks

          Comment

          • BSOB
            New Member
            • Jul 2006
            • 77

            #6
            'in general declaration
            Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As PointLocation, ByVal nCount As Long) As Long
            Public Type PointLocation
            X As Long
            Y As Long
            End Type
            Private m_Points(1 To 255) As PointLocation
            m_Points(1).X = X1
            m_Points(1).Y = Y1
            m_Points(2).X = x2
            m_Points(2).Y = y2
            m_Points(3).X = X3
            m_Points(3).Y = Y3
            m_Points(4).X = X4
            m_Points(4).Y = Y4
            Polygon Me.hdc, m_Points(1), 4
            'the 4 is the number of points of the polygon, you can set more points then 4 but you have to set values to those m_points x and y.


            'it sets that polygon (i think only pixels entirly within borders) to the forecolor (or maybe it was fill color).

            'if this doesnt work, let me know, ill see how i coded it.

            Comment

            • BSOB
              New Member
              • Jul 2006
              • 77

              #7
              oh yah, and from m_points(x)=... and down
              that isnt in general declaration any more, that is in your subroutine.

              Comment

              Working...