Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Code Samples & Tips Share your recent discoveries and ideas with other users.

Different Line Types

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-18-2008, 03:17 PM
ceaser's Avatar
Basic4ppc Veteran
 
Join Date: May 2008
Location: Paarl, South Africa
Posts: 312
Default Different Line Types

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
Reply With Quote
  #2 (permalink)  
Old 05-18-2008, 04:45 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

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,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
Reply With Quote
  #3 (permalink)  
Old 05-18-2008, 04:48 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

This is an example of drawing thick lines:
Code:
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
Reply With Quote
  #4 (permalink)  
Old 08-20-2008, 10:52 AM
Basic4ppc Veteran
 
Join Date: Apr 2008
Location: Gosford NSW Australia
Posts: 223
Send a message via MSN to tsteward
Default

Quote:
Originally Posted by Erel View Post
This is an example of drawing thick lines:
Code:
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
Reply With Quote
  #5 (permalink)  
Old 08-20-2008, 01:39 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 4,463
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Add the red line and you will have smouth lines with rounded ends.

Code:
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)
    <font color=
"Red">Control(Form,Form).Circle(x1,y1,penWidth/2,Pencolour,f)</font>
End Sub
Best regards.
__________________
Klaus
Switzerland

Beginner's Guide / User's Guide
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error when using an array of types zurpa Questions (Windows Mobile) 8 02-26-2011 07:41 AM
FileWrite at certain line..? TWELVE Questions (Windows Mobile) 3 08-31-2010 10:07 AM
Travian off-line stats... Cableguy Questions (Windows Mobile) 3 07-25-2008 04:55 AM
Error at line 0? Mistrel Questions (Windows Mobile) 9 11-04-2007 07:40 PM
How to draw a line? RandomCoder Questions (Windows Mobile) 3 08-24-2007 09:11 PM


All times are GMT. The time now is 09:55 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0