Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line clipping to arbitary 2D polygon

If I get a line segment which was long enough to cross a given polygon, which could be concave or convex polygon. How did I find the all the intersected light segments which was contained in the polygon?

alt text

If the target region is not polygon, but a implicit curve function or spline curve, how to do it?

Thanks!

like image 673
Buzz Avatar asked Oct 15 '10 08:10

Buzz


People also ask

Which algorithm is applied for clipping arbitrary polygons?

The Vatti clipping algorithm is used in computer graphics. It allows clipping of any number of arbitrarily shaped subject polygons by any number of arbitrarily shaped clip polygons.

Which is the best polygon clipping algorithm?

The Greiner-Hormann algorithm is used in computer graphics for polygon clipping. It performs better than the Vatti clipping algorithm, but cannot handle degeneracies. It can process both self-intersecting and non-convex polygons.

What is polygon clipping explain it?

Polygon clipping is defined by Liang and Barsky (1983) as the process of removing those parts of a polygon that lie outside a clipping window. A polygon clipping algorithm receives a polygon and a clipping window as input.

What are the various types of polygon clipping in computer graphics?

Four Cases of polygon clipping against one edge Case 1 : Wholly inside visible region - save endpoint. Case 2 : Exit visible region - save the intersection. Case 3 : Wholly outside visible region - save nothing. Case 4 : Enter visible region - save intersection and endpoint.


1 Answers

There really isn't a simple solution to your problem, especially with curves (beziers and splines). On top of the complexities of polygon clipping, there's the considerable challenge of reconstructing the clipped curves (assuming you want the clipping result to remain as beziers and splines and not just 'flattened' line approximations).

I have recently released a beta update* to my polygon clipping library 'Clipper' that does do line-polygon and line-line clipping (where lines can be curves too). However, while the main library is written in Delphi, C++ & C#, the new beta code is so far only in Delphi which may not help you. Nevertheless if you look at the code you'll see why I state there's no 'simple' solution.

  • Edit 15 Jul 2011: This 'update' never got beyond this beta release and is now simply 'proof-of-concept'. It is now based on an old version of my Clipper library and would need a major rewrite to be maintainable and extensible. (At some stage I may revisit it but I'm currently intent on further improving the core library.) Nevertheless, this 'proof-of-concept' Delphi code can be downloaded here

Clipper demo image

like image 137
Angus Johnson Avatar answered Sep 30 '22 13:09

Angus Johnson