How to calculate the intersection of CGPath and CGRect?

328 Views Asked by At

enter image description here

in IOS and MacOS platforms.

This is a CGPath object converted from Bezier curve. Now I have some regular rectangles and circles. I hope to calculate point1 and point2 points, which may not be particularly accurate.

I use swift language.

1

There are 1 best solutions below

0
Marcin Żmigrodzki On

The easiest but not accurate approach would be to assume, that bezier curve is actually straight within rectangle and circle. If so, you can count the point by counting sides of a triangle created by the beginning of the line and distance to the edge of rectangle or angle for circle and using Pitagoras theorem.