Android Code Snippet Cube-Spline Curve

Here is also an example of Cube-Spline made in B4A.
This is just an exercise, but can be used with appropriate modifications for other applications.

Good diversion ;)

ezgif.com-video-to-gif.gif


Here [XUI] Version
 

Attachments

  • cubespline.zip
    9.9 KB · Views: 669
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
One of the possible uses is the graphometric signature.
You memorize the main points of the signature and you can also build a soft path of the main points

I attached an image that I created with my source, just to give an idea.
In this demo I write the word "CORE"
video.gif
 

Joe73

Active Member
Licensed User
Hello,

A nice application. Thank you very much for that. I was looking for something like that.

Unfortunately, I couldn't program something like that myself.



Is there anything that can be improved?

Look at the picture, the long curves are a bit pixelated...

Yours sincerely Jürgen
 

Star-Dust

Expert
Licensed User
Longtime User
Non sono inglese ma ho impostato Google per la traduzione in inglese perché nel forum internazionale è richiesto l'inglese

Quindi per poter capire quello che chiedi devi scriverlo in inglese. Grazie
____________________________________________________
I'm not English but I set up Google for the English translation because English is required in the international forum

So in order to understand those you ask, you have to write it in English. Thank you
 

Star-Dust

Expert
Licensed User
Longtime User
Hello,

A nice application. Thank you very much for that. I was looking for something like that.

Unfortunately, I couldn't program something like that myself.



Is there anything that can be improved?

Look at the picture, the long curves are a bit pixelated...

Yours sincerely Jürgen
Addi this after Canvas Initialize
B4X:
Can.AntiAlias=true
 

Star-Dust

Expert
Licensed User
Longtime User
Grazie per il suggerimento, lo proverò.
Thanks for the tip, I'll test it.

greetings...
You can also try to create the canvas with double or triple dimensions of the view so that you raise the resolution or increase the thickness of the points so you do not want to leave.
_____________________________________________________
Sie können auch versuchen, die Leinwand mit doppelten oder dreifachen Dimensionen der Ansicht zu erstellen, sodass Sie die Auflösung erhöhen oder die Dicke der Punkte erhöhen, damit Sie nicht gehen möchten.
 

Star-Dust

Expert
Licensed User
Longtime User
... or draw a line from each point to the next point?
Actually it should produce points, but B4XCanvas does not have DrawPoint, so I used DrawCircle.

You can also use the lines to get continuity and not have gaps, but obviously it is a simplistic solution because it has to increase the density of the points, tracing lines you could get less soft curves.

But in the end what matters is the final result, if it is satisfactory for you to use it.

Mine is just an educational exercise to give ideas to others ... the rest you do it :p
 

Joe73

Active Member
Licensed User
Very well explained,
I don't understand how you can increase the density of the dots.
Can you help me with that?
Where do I start?

Thank you very much...

by the way, I use the DeepL translator, works very well....

Greeting Jürgen
 

Star-Dust

Expert
Licensed User
Longtime User
To increase the density you have to increase the points, 6 are very few, my example with 6 points is only educational.

There should be more points that draw a curve, but positioning them as you did, not the resultant is a very high sine wave and points distant from each other. If you need to draw points this way using C-Spline, then better use the lines as you suggest.
See this code:
B4X:
Private Sub DrawCSpline
    Dim piece As Int
    Dim xPos As Int
    Dim yPos As Int
    Dim lastx As Int = -1
    Dim lasty As Int = -1
 
    Dim Can As Canvas
    Can.Initialize(PanelMain)
    Can.DrawColor(Colors.White)
    Can.AntiAlias=True
 
    SetPandU
  
    For piece = 0 To Point.Length - 2
        For xPos = Point(piece).x To Point(piece + 1).x
            yPos = getCurvePoint(piece, xPos)
            If lastx=-1 And lasty=-1 Then Can.DrawCircle(xPos, yPos,1dip,Colors.Red,True,1dip)
              Can.DrawLine(lastx,lasty,xPos,yPos,Colors.Red,1dip)
            lastx=xPos
            lasty=yPos
        Next
    Next
End Sub

While with a few points and not adjacent you get excellent results with the bezier curves you find here
 
Last edited:

Joe73

Active Member
Licensed User
Yes, for example,
I measure the consumption of water,
I measure today, tomorrow and the day after tomorrow,
then in a week, two weeks, 15 days.
and in 20 days...
This is very irregular, but should result in a "nice" curve...

I want to use your code for this...

Greeting Jürgen
 

Joe73

Active Member
Licensed User
Your last SUB DrawCSpline works very well.
Only the start is a bit "unpleasant".
That will certainly be a minor problem.

Thank you very much for that.

I will continue testing...

Greeting Jürgen
 

Joe73

Active Member
Licensed User
Like this,
now it works...

Greetings...

B4X:
Private Sub DrawCSpline
    Dim piece As Int
    Dim xPos As Int
    Dim yPos As Int
    Dim lastx As Int = -1
    Dim lasty As Int = -1
 
    Dim Can As Canvas
    Can.Initialize(PanelMain)
    Can.DrawColor(Colors.White)
    Can.AntiAlias=True
 
    SetPandU
  
    For piece = 0 To Point.Length - 2
        For xPos = Point(piece).x To Point(piece + 1).x
            yPos = getCurvePoint(piece, xPos)
            If lastx=-1 And lasty=-1 Then
                Can.DrawCircle(xPos, yPos,1dip,Colors.Red,True,1dip)
                Else
                Can.DrawLine(lastx,lasty,xPos,yPos,Colors.Red,1dip)   
            End If
            lastx=xPos
            lasty=yPos
        Next
    Next
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
my mistake :p
 
Top