# Inaccurate y values in the distance function for Bezier clipping

This topic is 2468 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm currently working on implementing a curve intersection algorithm known as Bezier clipping, which is described towards the end of this article. I've been following through the article and source code (which can be found here) to implement it myself. A central part of this algorithm is the calculation of a "distance function" between curve2 and the baseline (a line running from start point to end point) of curve1. This seems to be where I've run into some trouble. When I draw out the distance function, the curve isn't anywhere near the other two curves, despite both clearly intersecting.

From what I can gather from the article (and my understanding could quite possibly be wrong), the calculation of the distance function is as follows.

The baseline is represented in the form x*a + y*b + c = 0, where a[sup]2[/sup] + b[sup]2[/sup] = 1. The coefficients a, b and c are calculated by rearranging the representation y = u*x + v, where u is the slope of the baseline ((y2 - y1)/(x2 - x1)), and x and y are any coordinate pairs that lie on the baseline. The formula can then be rearranged to v = y - u*x, and then rearranged to -u*x + 1*y - v = 0, meaning that a = -u, b = 1, and c = -v. To assure a[sup]2[/sup] + b[sup]2[/sup] = 1, all three coefficients are divided by a scalar of Math.sqrt(u[sup]2[/sup] + 1). This function is then substituted into the parametric formula of curve2, resulting in a bezier curve with Y[sub]i[/sub] = a*x[sub]i[/sub] + b*y[sub]i[/sub] + c (where x[sub]i [/sub]and y[sub]i [/sub]are the control points of curve2)and X[sub]i[/sub] = (1 - t)[sup]3[/sup]*y[sub]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634097
• Total Posts
3015495
×