• Create Account

# EVIL_ENT

Member Since 14 Aug 2010
Offline Last Active Apr 16 2016 09:35 AM

### Polygon Clipping

14 February 2012 - 01:27 PM

edit:
the jittering algorithm appears to fail in 0.1% of all cases
I'll try to find a better way

I implemented this polygon clipping algorithm
http://en.wikipedia....pping_algorithm

here you can see it working

solving degenerate cases is very troublesome though
at first I tried to handle every degenerate case properly but it seems to be very hard to impossible
since I don't need 1000% accuracy (I am fine with up to 0.5 pixel of jittering) I decided to randomly move polygon points until all degenerate cases are gone but I must have overlooked something

I am trying to get this to work since months so I decided to ask for help

the algorithm is supposed to subtract a polygon from another polygon and returns a list of polygons as a result of this subtraction
how it works:
1. create linked lists of vertices from both polygons
2. randomly move vertices until they are not on top of any lines
3. calculate all intersection points twice (once for each polygon) and connect them
4. insert intersection points into linked list of vertices
5. start at any intersection point and move through the linked list, swap list if another intersection point is reached

is there any easier way to deal with degenerate cases?

sidenote: I also tried java topology suite but for some reason it is a few tenthousand times slower (no exaggeration)

### Cut triangle with circle

14 November 2011 - 12:54 PM

I've got a triangle (black) and a circle-shaped n-gon (red).

Question:
How do I get the triangles covering the yellow area?

I tried calculating the triangle-circle-intersections to do something with them but then I noticed that there might be cases with no intersections at all.

### GIMP Brush Blending

09 July 2011 - 05:09 AM

I've got a line texture with soft edges.
If I render two of these lines above each other using
`glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);`
there's too much alpha where the lines are intersecting.

My blend function should do something like this:
```new color = old color or brush color//does not really matter because both are the same
if (old alpha > brush alpha) new alpha = old alpha
else new alpha = brush alpha```
So I could render the single brush strokes on a framebuffer object.
Next I could blend all these layers with
`glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);`
.

In the end it should look like in this video:

I've found several functions which work with alpha which are:
```glBlendEquation
glBlendEquationSeparate
glBlendFunc
glBlendFuncSeparate
glAlphaFunc```
but I got none of these to do what I want.
Test environment:
http://pastebin.com/HVPxtNa6

If it is possible with shaders some code would be very nice because I didn't work much with them yet.
Of course I could do this with the CPU and without OpenGL but that would be slower and I need it to be fast.

PARTNERS