Android Code Snippet Cube-Spline Curve

Discussion in 'Code Snippets' started by Star-Dust, Apr 25, 2018.

  1. Star-Dust

    Star-Dust Expert Licensed User

    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
     

    Attached Files:

    Last edited: Apr 25, 2018
  2. Star-Dust

    Star-Dust Expert Licensed 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
     
    Peter Simpson and Erel like this.
  3. Joe73

    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
     
  4. Joe73

    Joe73 Active Member Licensed User

    Screenshot_20180509-152744.jpg

    This is the pict.
     
  5. Star-Dust

    Star-Dust Expert Licensed 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
     
  6. Joe73

    Joe73 Active Member Licensed User

    Un mio errore, ora dovrebbe essere in inglese

    Saluti da Jürgen
     
  7. Star-Dust

    Star-Dust Expert Licensed User

    Addi this after Canvas Initialize
    Code:
    Can.AntiAlias=true
     
  8. Joe73

    Joe73 Active Member Licensed User

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

    greetings...
     
    Star-Dust likes this.
  9. Star-Dust

    Star-Dust Expert Licensed User

    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.
     
  10. Joe73

    Joe73 Active Member Licensed User

    It's not getting any better:

    Can.antialias=true
     
  11. Joe73

    Joe73 Active Member Licensed User

    ... or draw a line from each point to the next point?
     
  12. Star-Dust

    Star-Dust Expert Licensed User

    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
     
  13. Joe73

    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
     
  14. Star-Dust

    Star-Dust Expert Licensed 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:
    Code:
    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: May 9, 2018
  15. Joe73

    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
     
  16. Joe73

    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
     
  17. Star-Dust

    Star-Dust Expert Licensed User

  18. Joe73

    Joe73 Active Member Licensed User

    here the Pict.
    Screenshot_20180509-170024.jpg Screenshot_20180509-170037.jpg Screenshot_20180509-170042.jpg
     
  19. Joe73

    Joe73 Active Member Licensed User

    Like this,
    now it works...

    Greetings...

    Code:
    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 likes this.
  20. Star-Dust

    Star-Dust Expert Licensed User

    my mistake :p
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice