Android Question help me draw a key

tsteward

Well-Known Member
Licensed User
Longtime User
Can someone help create a routine to draw an outline of a key it doesn't need to be filled in like the one pictured.
I'm thinking of using the measurements supplied by the database to draw the key life size then scale it down to fit on a panel or something.
The number of cuts and depths can vary.

The image should be self-explanatory but if you need to know more, please let me know.
There are many keys in my database but doing this one will teach me enough to create other styles (I hope)
I have drawn a few lines but am failing dismally.

Happy to donate to a good solution.
 

Attachments

  • Screenshot 2021-07-01 185723.jpg
    55.1 KB · Views: 209

tsteward

Well-Known Member
Licensed User
Longtime User
Thinking something along the lines of
Sub drawkey(spaces as list, depths as list, cutWidth as int, keyBladeWidth as int, bitting as list)

Then can cycle through the spaces as list lengths will vary.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i dont know if this can help you but i played a little bit with b4j and this is what i got until now:



it can be modified and results can get much much better but i have not much time right now so i will post the code and now its your turn to play with b4j ?

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Type point(x As Float, y As Float)
    Private xAxis() As Float = Array As Float(300,510,720,930,1140,1350,1560,1770,1980,2300)
    Private yAxis() As Float = Array As Float(708,686,586,486,386,50)' 386,486,586,686,708)
    Private scaleFactorX = 0.2, scaleFaxotrY = 0.2 As Float
    Private cnv As B4XCanvas
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    cnv.Initialize(MainForm.RootPane)
    drawKey(Array As point(Createpoint(1,1),Createpoint(2,3),Createpoint(3,2),Createpoint(4,4),Createpoint(5,4),Createpoint(6,2),Createpoint(7,1),Createpoint(8,3),Createpoint(9,1),Createpoint(10,6)))
End Sub

Sub drawKey(l As List)
    cnv.ClearRect(cnv.TargetRect)
    Dim zeroLineY As Float = 200
    
    For i = 0 To l.Size-1
        Dim p As point = l.Get(i)
        cnv.DrawLine(xAxis(p.x-1)*scaleFactorX,0,xAxis(p.x-1)*scaleFactorX,1000,xui.Color_DarkGray,1)
        cnv.DrawLine(xAxis(p.x-1)*scaleFactorX,0,xAxis(p.x-1)*scaleFactorX,1000,xui.Color_DarkGray,1)
        cnv.DrawLine(0,zeroLineY-((yAxis(p.y-1)/2)*scaleFaxotrY),1000,zeroLineY-((yAxis(p.y-1)/2)*scaleFaxotrY),xui.Color_DarkGray,1)
        cnv.DrawLine(0,zeroLineY+((yAxis(p.y-1)/2)*scaleFaxotrY),1000,zeroLineY+((yAxis(p.y-1)/2)*scaleFaxotrY),xui.Color_DarkGray,1)
        cnv.DrawCircle(xAxis(p.x-1)*scaleFactorX,zeroLineY-((yAxis(p.y-1)/2)*scaleFaxotrY),3,xui.Color_Red,True,0)
        cnv.DrawCircle(xAxis(p.x-1)*scaleFactorX,zeroLineY+((yAxis(p.y-1)/2)*scaleFaxotrY),3,xui.Color_Red,True,0)
        
        If i > 0 Then
            Dim champfer As Float = (210*scaleFaxotrY)*0.35
            Dim p0 As point = l.Get(i-1)
            If i > l.Size-3 Then champfer = ((xAxis(p.x-1)-xAxis(p0.x-1))*scaleFactorX) 'fullchampfer
            cnv.DrawLine(xAxis(p0.x-1)*scaleFactorX,zeroLineY-((yAxis(p0.y-1)/2)*scaleFaxotrY),(xAxis(p0.x-1)*scaleFactorX)+champfer,zeroLineY-((yAxis(p.y-1)/2)*scaleFaxotrY),xui.Color_Blue,2)
            cnv.DrawLine(xAxis(p0.x-1)*scaleFactorX,zeroLineY+((yAxis(p0.y-1)/2)*scaleFaxotrY),(xAxis(p0.x-1)*scaleFactorX)+champfer,zeroLineY+((yAxis(p.y-1)/2)*scaleFaxotrY),xui.Color_Blue,2)
            cnv.DrawLine((xAxis(p0.x-1)*scaleFactorX)+champfer,zeroLineY-((yAxis(p.y-1)/2)*scaleFaxotrY),xAxis(p.x-1)*scaleFactorX,zeroLineY-((yAxis(p.y-1)/2)*scaleFaxotrY),xui.Color_Blue,2)
            cnv.DrawLine((xAxis(p0.x-1)*scaleFactorX)+champfer,zeroLineY+((yAxis(p.y-1)/2)*scaleFaxotrY),xAxis(p.x-1)*scaleFactorX,zeroLineY+((yAxis(p.y-1)/2)*scaleFaxotrY),xui.Color_Blue,2)
        End If
    Next
End Sub
 
Public Sub Createpoint (x As Float, y As Float) As point
    Dim t1 As point
    t1.Initialize
    t1.x = x
    t1.y = y
    Return t1
End Sub
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Thanks I'll have a look.

With what appeared to be no interest I have been experimenting and came up with this so far.
 

Attachments

  • Screenshot_20210704-200127.jpg
    256 KB · Views: 176
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…