B4J Question How to Draw Cardinal Splines similar to Visual Studio?

rtek1000

Active Member
Licensed User
Longtime User
I found very interesting graphical examples, but I haven't found a function that has good compatibility with the code described below:

B4X:
Point[] points = {
   new Point(60, 60),
   new Point(150, 80),
   new Point(200, 40),
   new Point(180, 120),
   new Point(120, 100),
   new Point(80, 160)};

Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawClosedCurve(pen, points);

bell-shaped-cardinal-spline.png


Source: https://docs.microsoft.com/en-us/do...cardinal-splines?view=netframeworkdesktop-4.8

I would like to get a result similar to a tension argument equal to 1.0:

three-cardinal-splines.png



B4X:
point_x: 0, 0.01318359375, 0.05126953125, 0.08935546875, 0.1259765625, 0.1640625, 0.1962890625, 0.22998046875, 0.2578125, 0.28564453125, 0.31201171875, 0.333984375, 0.35302734375, 0.369140625, 0.380859375, 0.38818359375, 0.39404296875, 0.39404296875, 0.392578125, 0.38525390625, 0.375, 0.35888671875, 0.34130859375, 0.32080078125, 0.2958984375, 0.26953125, 0.240234375, 0.20947265625, 0.17724609375, 0.140625, 0.1025390625, 0.06591796875, 0.0263671875, -0.01318359375, -0.0498046875, -0.087890625, -0.123046875, -0.1611328125, -0.19482421875, -0.2255859375, -0.2548828125, -0.28271484375, -0.30908203125, -0.32958984375, -0.3486328125, -0.36328125, -0.37646484375, -0.3837890625, -0.3896484375, -0.3896484375, -0.38818359375, -0.37939453125, -0.37060546875, -0.3544921875, -0.33984375, -0.31787109375, -0.29150390625, -0.2666015625, -0.2373046875, -0.2080078125, -0.17578125, -0.1376953125, -0.10107421875, -0.064453125
point_y: 0.49658203125, 0.52294921875, 0.5244140625, 0.521484375, 0.52294921875, 0.521484375, 0.52001953125, 0.51708984375, 0.51708984375, 0.51708984375, 0.5126953125, 0.51123046875, 0.509765625, 0.50830078125, 0.50390625, 0.50390625, 0.498046875, 0.498046875, 0.4921875, 0.4921875, 0.48779296875, 0.486328125, 0.4833984375, 0.48193359375, 0.47900390625, 0.47900390625, 0.47607421875, 0.47607421875, 0.47314453125, 0.47021484375, 0.47314453125, 0.47021484375, 0.47021484375, 0.47314453125, 0.47021484375, 0.47314453125, 0.47021484375, 0.47314453125, 0.474609375, 0.474609375, 0.47900390625, 0.47900390625, 0.48193359375, 0.48193359375, 0.48486328125, 0.48486328125, 0.49072265625, 0.49072265625, 0.49658203125, 0.49658203125, 0.50244140625, 0.5009765625, 0.5068359375, 0.5068359375, 0.51123046875, 0.5126953125, 0.515625, 0.51416015625, 0.51708984375, 0.5185546875, 0.521484375, 0.52294921875, 0.521484375, 0.5244140625

The values above generate this curve in Visual Studio:
ref.png


Using the example code from this link https://www.b4x.com/android/forum/threads/cube-spline-curve.92306/#content I managed to get this image:
result.png


It is very similar, because the dots were drawn, but it was not able to connect the dots with a smooth line.

Does anyone know if there is any library available for this function?


Other examples I found, but I couldn't test them all in B4J:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 0
Top