 |

06-16-2010, 01:32 AM
|
|
Newcomer
|
|
Join Date: Jun 2010
Posts: 3
|
|
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
|
|

06-22-2010, 01:28 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
|
|
|
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.
|

06-23-2010, 12:35 AM
|
|
Newcomer
|
|
Join Date: Jun 2010
Posts: 3
|
|
Quote:
Originally Posted by passel
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
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|