Results 1 to 4 of 4

Thread: Create a Polygon with no Intersecting Lines

  1. #1

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Create a Polygon with no Intersecting Lines

    Hello!

    Today I would like to learn how to create a polygon without any intersecting lines. How can this be done?

    Thanks.

    This is something I just wrote to create any random polygon.

    vb Code:
    1. Private Sub CreatePolygon(ByRef Color As Color, ByRef LocationBounds As Rectangle, Optional ByRef NumberOfPoints As Int32 = 10)
    2.         Dim R As New Random
    3.         Dim PolygonPointsList As New List(Of Point)
    4.         Dim PolygonArray() As Point
    5.         Dim G1 As Graphics = Me.CreateGraphics
    6.         Dim Sb As New SolidBrush(Color)
    7.         For i As Int32 = 1 To NumberOfPoints Step 1
    8.             Dim NewPt As New Point(CInt(R.Next(LocationBounds.X, LocationBounds.X + LocationBounds.Width)), _
    9.                                    CInt(R.Next(LocationBounds.Y, LocationBounds.Y + LocationBounds.Height)))
    10.             PolygonPointsList.Add(NewPt)
    11.         Next
    12.         PolygonArray = PolygonPointsList.ToArray
    13.         Me.Refresh()
    14.         G1.FillPolygon(Sb, PolygonArray)
    15.     End Sub

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,522

    Re: Create a Polygon with no Intersecting Lines

    If the lines don't intersect, they are parallel. If the lines are parallel, they are by definition not a polygon... by its very definition a polygon has to have intersecting lines. Otherwise you just have a bunch of lines that are meaningless.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,458

    Re: Create a Polygon with no Intersecting Lines

    @NinjaNic

    You mean a polygon whose lines only meet at the vertices?

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,698

    Re: Create a Polygon with no Intersecting Lines

    I have a random polygon creator in the codebank:
    http://www.vbforums.com/showthread.p...hlight=polygon

    I remember needing it for an asteroid game that I never finished.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width