1. ## 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. Doesn't anyone have an idea? What kind of a game programming forum is this anyway?

3. 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.

4. 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

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. 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..

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.

6. 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. > 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).

8. 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

9. 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. 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.