Anyone have any knowledge of a function that returns the intersection TPath for two TShapes? Especially one that returns the intersection TPath of two TPaths.
For instance:
pthIntersection := PathIntersection(Path1,Path2);
Anyone have any knowledge of a function that returns the intersection TPath for two TShapes? Especially one that returns the intersection TPath of two TPaths.
For instance:
pthIntersection := PathIntersection(Path1,Path2);
There is no built-in function for this.
But what I think you are trying to do is this:
Given a polygon (aka TPath) made up for distinct points connected by lines.
Return all points in ShapeA that lay inside ShapeB.
Point intersection
This can be done using
PointInObjectLocal
.Run a loop visiting all points in
PathA
and see if any lay insidePathB
.Line intersection
If you want to know all vertices that overlap you'll first have to
Flatten
(a copy) of both TPaths and then run a line intersect algorithm for all lines in both shapes.This converts all curves to lines.
Here's a routine to do just that:
From: http://www.partow.net/projects/fastgeo/index.html
Just convert the
TFloat
x,y pairs toTPointF
and you're in business. The cool thing about the routine is that it also tells you the exact point at which the lines overlap.If you follow the lines, until two lines overlap and from there on start tracking both overlapping lines and PointInShape you can construct an exact image of the overlap of the two shapes.
Making it faster
If the flattening and the corresponding increase in the number of line segments make your code too slow you can keep the curves and see if a line/curve intersects another curve.
For this you can convert the curves into bezier curves and use De_Casteljau's algorithm
More info
See also this question and the link to Delphi source code in its first or second answer.