  # Different Line Types

Discussion in 'Code Samples & Tips' started by ceaser, May 18, 2008.

1. 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:

2. 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)
Code:
`Sub Globals    'Declare the global variables here.    Dim xx,yyEnd SubSub App_Start    Form1.ShowEnd SubSub 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    NextEnd SubSub Form1_MouseDown (x,y)    DashLine(5,xx,yy,x,y,cBlue)    xx = x    yy = yEnd Sub`

3. This is an example of drawing thick lines:
Code:
`Sub Globals    Dim Type(x,y) points(0)End SubSub App_Start    Form1.Show    DrawThickLine ("Form1",20,30,20,200,10,cGold)    DrawThickLine ("Form1",20,30,70,44,10,cRed)End SubSub 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`

4. 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?
`Sub Globals    Dim Type(x,y) points(0)End SubSub App_Start    Form1.Show    DrawThickLine ("Form1",20,30,20,200,10,cGold)    DrawThickLine ("Form1",20,30,70,44,10,cRed)End SubSub 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`