Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Interface and Graphics > Drawing Radar


Reply
 
Thread Tools Display Modes
  #1  
Old 06-16-2010, 01:32 AM
danielsii danielsii is offline
Newcomer
 
Join Date: Jun 2010
Posts: 3
Default Drawing Radar


Below is the code i found and edited a little bit. Can anyone teach me how to draw a dot (with XY position) in the radar. Thanks in advance.

Code:
    ' Draw the radar plot.
    Private Sub picCanvas_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picCanvas.Paint
        ' Generate coordinates for the points.
        Dim pts(m_RData.Length - 1) As PointF
        Dim theta As Single = 0
        Dim dtheta As Single = CSng(2 * PI / (m_RData.Length - 1))
        For i As Integer = 0 To m_RData.Length - 1
            pts(i) = New PointF( _
                CSng(m_RData(i) * Cos(theta)), _
                CSng(m_RData(i) * Sin(theta)))
            theta += dtheta
        Next i

        ' Find the largest value so we can scale nicely
        Dim max_r As Single = m_RData(0)
        For i As Integer = 0 To m_RData.Length - 1
            If max_r < m_RData(i) Then max_r = m_RData(i)
        Next i

        ' Transform to scale the result
        Dim the_scale As Single = _
            CSng(Min(picCanvas.ClientSize.Width, _
                     picCanvas.ClientSize.Height) / 2 / max_r)
        e.Graphics.ScaleTransform( _
            the_scale, the_scale, _
            Drawing2D.MatrixOrder.Append)

        ' Transform to center the result
        e.Graphics.TranslateTransform( _
            picCanvas.ClientSize.Width \ 2, _
            picCanvas.ClientSize.Height \ 2, _
            Drawing2D.MatrixOrder.Append)

        ' Draw
        e.Graphics.Clear(picCanvas.BackColor)

        ' Draw the radar graph
        e.Graphics.FillPolygon(Brushes.LightBlue, pts)
        Dim black_pen As New Pen(Color.Black, 0)
        e.Graphics.DrawPolygon(black_pen, pts)
        black_pen.Dispose()

        ' Draw radius
        Dim blue_pen As New Pen(Color.Blue, 0)
        For i As Integer = 0 To pts.Length - 1
            e.Graphics.DrawLine(blue_pen, _
                New PointF(0, 0), pts(i))
        Next i
        blue_pen.Dispose()

        ' Draw radius circles.
        If IsNumeric(2) Then
            Dim circle_increment As Single = _
                CSng(Val(2))
            Dim white_pen As New Pen(Color.Red, 0)
            For r As Single = circle_increment To max_r + 1 Step circle_increment
                e.Graphics.DrawEllipse(white_pen, -r, -r, 2 * r, 2 * r)
            Next r
            white_pen.Dispose()
        End If

    End Sub
Reply With Quote
  #2  
Old 06-22-2010, 01:28 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
Default

If you look at the line five lines from the end of your sub, you have:
e.Graphics.DrawEllipse(white_pen, -r, -r, 2 * r, 2 * r)

Using that line as an example, at a line at the end of your sub for testing, add a FillElipse call.

If you use FillEllipse instead of DrawEllipse, you will draw a filled circle.
If you use a value for x, y and hs for HalfSize(or radius),
e.Graphics.FillEllipse(white_pen, x - hs, y - hs, 2 * hs, 2 * hs)

will draw a solid circle with radius hs centered at x, y.

Your X=0, Y=0 location is the center of the radar image at this point.
The size of the point that hs represents will depend on the scale of your radar display set above, which was based on the largest value (radius) specified in your m_RData array.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 06-22-2010 at 01:33 PM.
Reply With Quote
  #3  
Old 06-23-2010, 12:35 AM
danielsii danielsii is offline
Newcomer
 
Join Date: Jun 2010
Posts: 3
Cool

Quote:
Originally Posted by passel View Post
If you look at the line five lines from the end of your sub, you have:
e.Graphics.DrawEllipse(white_pen, -r, -r, 2 * r, 2 * r)

Using that line as an example, at a line at the end of your sub for testing, add a FillElipse call.

If you use FillEllipse instead of DrawEllipse, you will draw a filled circle.
If you use a value for x, y and hs for HalfSize(or radius),
e.Graphics.FillEllipse(white_pen, x - hs, y - hs, 2 * hs, 2 * hs)

will draw a solid circle with radius hs centered at x, y.

Your X=0, Y=0 location is the center of the radar image at this point.
The size of the point that hs represents will depend on the scale of your radar display set above, which was based on the largest value (radius) specified in your m_RData array.

Thanks. It is of great help
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->