Different Line Types

ceaser

Active Member
Licensed User
Hi

I wonder if anybody can help me? While I am busy with a Topographical survey, the points get plotted on the screen as they come from the Total Station or GPS. I can then add lines, text, circles, etc to the surveyed points, which means that the drawing will be nearly finished when I go back to the office.

My question is, is there any way that I can have different line types, i.e. solid, dashed, dot dashed, etc.

Thanks
Michael:sign0085:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You will need to write the drawing algorithms yourself.
The following code demonstrates a simple way to draw dashed lines:
(length is the length of each section in the dashed line)
B4X:
Sub Globals
    'Declare the global variables here.
    Dim xx,yy
End Sub

Sub App_Start
    Form1.Show
End Sub

Sub DashLine(length,x1,y1,x2,y2,color)
    b = ATan((y2-y1)/(x2 + 0.00001 - x1))
    total = Sqrt((x2-x1)^2+(y2-y1)^2)
    x = x1
    y = y1
    cs = Cos(b) * length
    sn = Sin(b) * length
    If x2 < x1 Then 
        cs = -cs
        sn = -sn
    End If
    For i = 0 To total Step 2*length
        xEnd = x + cs
        yEnd = y + sn
        form1.Line(x,y,xend,yend,color)
        x = xEnd + cs
        y = yEnd + sn
    Next
End Sub


Sub Form1_MouseDown (x,y)
    DashLine(5,xx,yy,x,y,cBlue)
    xx = x
    yy = y
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is an example of drawing thick lines:
B4X:
Sub Globals
    Dim Type(x,y) points(0)
End Sub

Sub App_Start
    Form1.Show
    DrawThickLine ("Form1",20,30,20,200,10,cGold)
    DrawThickLine ("Form1",20,30,70,44,10,cRed)
End Sub

Sub DrawThickLine(Form, x1, y1, x2, y2, width, color)
    l = ATan((y2-y1)/(x2-x1+0.01))
    dx = width/2 * Sin(l)
    dy = width/2 * Cos(l)
    points() = Array((x1 + dx,y1 - dy),(x2 + dx,y2 - dy), _
                (x2 - dx,y2 + dy),(x1 - dx,y1 + dy))
    Control(Form,Form).Polygon(points(),0,4,color,f)
End Sub
 

tsteward

Well-Known Member
Licensed User
Longtime User
This is an example of drawing thick lines:
B4X:
Sub Globals
    Dim Type(x,y) points(0)
End Sub

Sub App_Start
    Form1.Show
    DrawThickLine ("Form1",20,30,20,200,10,cGold)
    DrawThickLine ("Form1",20,30,70,44,10,cRed)
End Sub

Sub DrawThickLine(Form, x1, y1, x2, y2, width, color)
    l = ATan((y2-y1)/(x2-x1+0.01))
    dx = width/2 * Sin(l)
    dy = width/2 * Cos(l)
    points() = Array((x1 + dx,y1 - dy),(x2 + dx,y2 - dy), _
                (x2 - dx,y2 + dy),(x1 - dx,y1 + dy))
    Control(Form,Form).Polygon(points(),0,4,color,f)
End Sub

Hey this is pretty good. Thanks Erel.
Now the maths in the above routine is way over my head but, the lines are not very smooth.
Can anyone improve this?
Please
Or is this as good as it gets?

Thanks
Tony
 

klaus

Expert
Licensed User
Longtime User
Add the red line and you will have smouth lines with rounded ends.

B4X:
Sub Globals
    Dim Type(x,y) points(0)
End Sub

Sub App_Start
    Form1.Show
    DrawThickLine ("Form1",20,30,20,200,10,cGold)
    DrawThickLine ("Form1",20,30,70,44,10,cRed)
End Sub

Sub DrawThickLine(Form, x1, y1, x2, y2, width, color)
    l = ATan((y2-y1)/(x2-x1+0.01))
    dx = width/2 * Sin(l)
    dy = width/2 * Cos(l)
    points() = Array((x1 + dx,y1 - dy),(x2 + dx,y2 - dy), _
                (x2 - dx,y2 + dy),(x1 - dx,y1 + dy))
    Control(Form,Form).Polygon(points(),0,4,color,f)
    [COLOR="Red"]Control(Form,Form).Circle(x1,y1,penWidth/2,Pencolour,f)[/COLOR]
End Sub

Best regards.
 
Top