Quadratic curve fitting has a "bump" midway down the curve

30 Views Asked by At

I am working with some code to calculate a curved wheel profile that is used to generate a program for a CNC machine using best-fit coefficients that correspond to a quadratic equation in the form below:

$y = ax^{2} + b + c$

I already have code to find the coefficients a, b and c using matrices and I am using 3 fixed points on the profile:

  • Start of profile (S)
  • Midpoint of profile (M)
  • End of profile (E)

I am treating the flank as having 2 segments:

  1. S-M: $\delta Y_{1} = (Y_{M} - Y_{S})$

n = number of points between M and S

$\gamma Y_{1} = (\delta Y_{1} \div n)$

  1. M-E: $\delta Y_{2} = (Y_{M} - Y_{E})$

n = number of points between M and E

$\gamma Y_{2} = (\delta Y_{2} \div n)$

I calculate the Y coordinate for each point as follows:

  • S-M: $Y_{i} = (Y_{i + 1} - \gamma Y_{1})$
  • M-E: $Y_{i} = (Y_{i + 1} - \gamma Y_{2})$

This means that the points should be equally spaced out on the Y axis in each segment.

I calculate the X coordinate for each point as follows:

  • S-M: $X_{i} = SolveQuadraticForX(A_{1}, B_{1}, C_{1}, Y_{i}, 1)$
  • M-E: $X_{i} = SolveQuadraticForX(A_{2}, B_{2}, C_{2}, Y_{i}, 1)$

I switch from set "1" to set "2" at the midpoint (M).

What I am seeing is a "bump" (for want of a better word) on the curve around the midpoint where I switch segments and I would like to be able to remove this but all I have been able to do so far is to reduce the size of it.

I have tried changing where the segment switch takes place in relation to point M, but I am coming around to thinking that perhaps I should have a set of coefficients, "n", "$\delta Y$" and "$\gamma Y$" that relate to the entire flank between points S and E, and then use that to assist in fitting the curve around the midpoint.

The reason why this profile has a switch around the midpoint is that it is calculated from a worm profile which is defined using 3 diameter parameters (amongst others): root diameter, reference circle diameter (aka pitch circle diameter) and tip diameter.

The worm profile is calculated using one radius increment between the tip & pitch circle and then using a second radius increment between the pitch circle and root, and this is carried across to the wheel profile calculations.

Does anyone have any advice on what I can modify to correct this "bump" as I am sure that I am missing something but it is not coming to me at the moment?