Thread: 2D Clipping

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    19

    2D Clipping

    Anyone know how to clip a convex polygon against another convex polygon?

    The basic algorithm goes like this:

    for every edge of the clipping region
    for every edge of the polygon
    clip polygon against clipipng region line

    I can't figure out the details of this algorithm. (i.e how to communicate the vertex data from one iteration to the next)

    Don't post replies about clipping lines ( i am well aware of the mathematics behind it ).

    Duetti

  2. #2
    Registered User
    Join Date
    Nov 2003
    Posts
    19
    Doesn't anyone have an idea? What kind of a game programming forum is this anyway?

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Do you know how to clip a line to a polygon? Why don't you start with that and then try clipping polygons to polygons. I don't even know what you mean when you say

    (i.e how to communicate the vertex data from one iteration to the next)
    Also don't get all mad when people don't answer your question. Some people on here have lives outside of the internet.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    19
    Read all previous posts before posting "MrWizard".

    > Do you know how to clip a line to a polygon?

    From my original post...
    Don't post replies about clipping lines ( i am well aware of the mathematics behind it ).
    > I don't even know what you mean when you say
    (i.e how to communicate the vertex data from one iteration to the next)
    From my original post..
    The basic algorithm goes like this:

    for every edge of the clipping region
    for every edge of the polygon
    clip polygon against clipping region line
    As I said, read all previous posts before posting your reply.

    > Also don't get mad when people don't answer your question

    I am not mad, I am just really surprised that I can't get an answer to such a classic graphic's programming problem in a "game programming forum".

    > Some people on here have lives outside of the internet.

    Did I suggest otherwise? Judging from your number of posts(1070), it's YOU that has been spending quite a lot of YOUR time online, not me. :-)

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Duetti
    Read all previous posts before posting "MrWizard".

    > Do you know how to clip a line to a polygon?

    From my original post...


    > I don't even know what you mean when you say

    From my original post..


    As I said, read all previous posts before posting your reply.

    > Also don't get mad when people don't answer your question

    I am not mad, I am just really surprised that I can't get an answer to such a classic graphic's programming problem in a "game programming forum".

    > Some people on here have lives outside of the internet.

    Did I suggest otherwise? Judging from your number of posts(1070), it's YOU that has been spending quite a lot of YOUR time online, not me. :-)
    Just because you know the mathematics does NOT mean you know how to program it. What I meant was have you written a program to clip a line to a polyogn, if not do that first. Of course I read all of the post before I posted. I can't believe you can't figure out such a simple algorithm to be honest. If you know the mathematics behind it, it pratically writes itself. I was going to help you out but I changed my mine. Best of luck.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Doesn't anyone have an idea? What kind of a game programming forum is this anyway?
    Um hate to tell you but THIS ISN'T A GAME PROGRAMMING FORUM! This is a C/C++/C# programming forum. We just happened to have a bunch of people interested in game programming so an area was made to keep those posts to gether. Try going to a forum that solely focused on Game programming.
    Also its considered rude when a new person to the forum gets snippy with a established person when they try to lend a hand.

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    19
    > Just because you know the mathematics does NOT mean you know how to program it. What I meant was have you written a program to clip a line to a polyogn, if not do that first.

    No it doesn't. Yes, I am able to clip a line against a convex polygonal region.

    First you were sarcastic,
    Some people on here have lives outside of the internet.
    now you, indirectly, call me an idiot (or incompetent).
    I can't believe you can't figure out such a simple algorithm to be honest.
    How old are you? Maybe you'd like to meet me at the playground after school? :-) (my turn to be sarcastic)

    > If you know the mathematics behind it, it pratically writes itself

    For the third time, I know the mathematics behind line clipping, NOT polygon clipping.

    > I was going to help you out but I changed my mine.

    No worries. :-)

    > Best of luck

    Thank you.

    > Um hate to tell you but THIS ISN'T A GAME PROGRAMMING FORUM!

    You are right, wrong choice of words. It's not a forum, it's a board.
    I've read many threads on this board and they are mostly about graphic's programming. That's why I was surpised.

    > Also its considered rude when a new person to the forum gets snippy with a established person when they try to lend a hand.

    MrWizard didn't lend a hand. He replied without reading my initial post(or paying too much attention to it) and was rather sarcastic (near the end of his post).
    Last edited by Duetti; 12-03-2003 at 06:17 PM.

  8. #8
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    MrWizard didn't lend a hand. He replied without reading my initial post(or paying too much attention to it) and was rather sarcastic (near the end of his post).
    Right...So it's our problem to figure out what posts (if any) pertain to this thread? If you are posting a follow-up, then post a link to the original thread(s).

    A polygon is simply a collection of vertices...If you can figure out how to get an equation out of two points, then you should be able to clip a polygon as if it were just several lines
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  9. #9
    Registered User
    Join Date
    Nov 2003
    Posts
    19
    Alright, we clip a line segment by looping through the clipping region's edges.

    We clip a polygon by clipping it against each edge of the clipping region. Like so:

    Code:
    for every edge in the clipping region
       for every edge in the polygon
          clip it against the current clipping region's edge
    In the inner loop, we loop through all of the polygon's edges and we clip them against the current clipping region's edge.

    After one iteration of the inner loop, the polygon has been clipped against one of the edges of the clipping region, thus producing a new polygon. This new polygon will become the source polygon for the next iteration of the outer loop.

    I just can't describe this algorithm in more detail so that I can code it, that's why I've asked for your help.
    Give me code or pseudocode, suggest books or online tutorials, something to help me understand.

    Duetti

  10. #10
    Registered User
    Join Date
    Oct 2003
    Posts
    13
    Originally posted by Duetti

    Did I suggest otherwise? Judging from your number of posts(1070), it's YOU that has been spending quite a lot of YOUR time online, not me. :-) [/B]
    It's called time effect. After over a year and a couple months until two... 1000 isn't a lot.

  11. #11
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    This thread is closed

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  2. 2D in directX
    By fighter92 in forum Game Programming
    Replies: 6
    Last Post: 01-25-2009, 11:23 AM
  3. Best Graphics Library for 2d RTS?
    By arew264 in forum Game Programming
    Replies: 4
    Last Post: 04-18-2007, 12:05 PM
  4. Replies: 16
    Last Post: 09-22-2006, 03:39 PM
  5. Read file in 2D array
    By Chook in forum C Programming
    Replies: 1
    Last Post: 05-08-2005, 12:39 PM