0

I have an NSBezierPath. I would like to interpolate along in a way that

interpolate (0) = starting point
interpolate (1) = end point
interpolate (0.5) = middlePoint. 

I would like as well a function that provides a normal vector at the point.

I saw a lot of puzzle pieces during my search but nobody offering a full solution in swift. Key problems are:

  • how can I ensure that interpolate(0.5) is really in the middle of the path? Do I need to consider the length of the overall path? Will it always be the middle point of the middle path segment? I doubt that. However, good approximations are welcome!
  • how do I retrieve the normal vector on such a point?

Many thanks in advance!

Wizard of Kneup
  • 1,863
  • 1
  • 18
  • 35

1 Answers1

0

Basically, I used this library: https://github.com/louisdh/bezierpath-length/blob/master/Source/BezierPath%2BLength.swift

It gave me a good approximation of the x that is needed in order to do the interpolation after a small change. With that x and this explanation: https://medium.com/@adrian_cooney/bezier-interpolation-13b68563313a was I able to find the normal vector (the last interpolation is along the tangent, so I only needed the orthogonal vector from that last interpolation).

My code is still a bit messy. I might publish later. But it works!

Wizard of Kneup
  • 1,863
  • 1
  • 18
  • 35