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?
If the target region is not polygon, but a implicit curve function or spline curve, how to do it?
Thanks!
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With