# Math question a function to draw a curve from linear passing by cos and beyond, pivotating in the middle point

Hi people.

I have a need to adjust the curve of the following picture dinamically.
Today I can plot the linear (0) and the cos curve (1 like), but anything in the middle or more radical like curve 3 I have no math skills to find a parameterizable function that could plot all scenarios.

Anyone could help me where or how can I can find this ?

Thank you

Bezier curves or B-splines

Many drawing programs feature them as tools. Check Wikipedia

Thanks jremington.
I´ll search some library to calculate inside arduino, but a fast reading on Bezier seems to draw the curves with a few predefined points.

Thanks!!

What library did you end up using? It would be helpful to others if you posted a link, or code. I did a quick look and did not find an Arduino example.

Hi JRemington

first thanks for the insight.
Sorry not to update the thread as I only finished my application yesterday afternoon, around 4am.

My application has a huge overhead so I opted to generate my curves offline and load them via PROGMEM.

https://github.com/luisllamasbinaburo/Arduino-Interpolation

but had only used linear interpolation. I forgot that the library has 2 spline examples that were my solution.
Then I went into Corel Draw and drew the full-size curves I needed and used the Corel coordinates to annotate the necessary points.

I imported the points into the sketch that will generate my curves, which was as follows;

``````#include <InterpolationLib.h>

#define NUMPOINTS 12

double xValues0[NUMPOINTS] = {0, 1, 432, 1592, 2852, 3600, 4096, 4595, 5530, 6750, 7763, 8192};
double yValues0[NUMPOINTS] = {0, 1, 432, 1592, 2852, 3600, 4096, 4595, 5530, 6750, 7763, 8192};
double xValues1[NUMPOINTS] = {0, 1, 438, 1688, 3018, 3700, 4096, 4498, 5352, 6652, 7754, 8192};
double yValues1[NUMPOINTS] = {0, 1, 351, 1435, 2779, 3583, 4096, 4607, 5600, 6905, 7854, 8192};
double xValues2[NUMPOINTS] = {0, 1, 449, 1827, 3234, 3820, 4096, 4377, 5133, 6528, 7739, 8192};
double yValues2[NUMPOINTS] = {0, 1, 254, 1213, 2685, 3569, 4096, 4623, 5727, 7041, 7949, 8192};
double xValues3[NUMPOINTS] = {0, 1, 461, 1980, 3476, 3932, 4096, 4261, 4848, 6400, 7734, 8192};
double yValues3[NUMPOINTS] = {0, 1, 167, 974, 2578, 3554, 4096, 4638, 5862, 7400, 8049, 8192};
double xValues4[NUMPOINTS] = {0, 1, 477, 2193, 3758, 4057, 4096, 4139, 4590, 6244, 7717, 8192};
double yValues4[NUMPOINTS] = {0, 1, 29, 633, 2473, 3537, 4096, 4651, 6011, 7678, 8161, 8192};

void setup()
{
Serial.begin(115200);
// Serial.println("const uint16_t bezierCurve0 PROGMEM = {");
// for (double point = 0; point < 8192; point++)//use this FOR only to create final array

for (double point = 0; point < 8192; point += 30) //use this FOR to experiment values and coordinates
{
Serial.print(point / 2, 0); //linear
Serial.print(",");
Serial.print(Interpolation::ConstrainedSpline(xValues0, yValues0, NUMPOINTS, point, true) / 2, 0);
Serial.print(",");
Serial.print(Interpolation::ConstrainedSpline(xValues1, yValues1, NUMPOINTS, point, true) / 2, 0);
Serial.print(",");
Serial.print(Interpolation::ConstrainedSpline(xValues2, yValues2, NUMPOINTS, point, true) / 2, 0);
Serial.print(",");
Serial.print(Interpolation::ConstrainedSpline(xValues3, yValues3, NUMPOINTS, point, true) / 2, 0);
Serial.print(",");
Serial.print(Interpolation::ConstrainedSpline(xValues4, yValues4, NUMPOINTS, point, true) / 2, 0);
Serial.print(",");
// if (!((uint16_t)point % 20)) //CRLF when generate final array
Serial.println("");
}
//Serial.println("}"); //use only when generate final array
}

void loop()
{
}

``````

In the end I imported all arrays for my final application to do the needed math.