Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Graphing a Circle in a Coordinate Plane with inputs Center and Radius

visual basic visual basic 2010 oop graphing circle

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 angel06

angel06

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 17 October 2015 - 04:28 AM

I'm trying to plot a circle on a Coordinate Plane. Now my problem is that whenever I'm trying to input something (for example, C:0,0 R:10), it doesn't plot correctly in the cartesian coordinate plane.

 

I've been trying to solve this for like hours but it seems like I can't fix this on my own. I think my problem lies within the Button1_Click event, I've tried changing the values of variables x, y and r but still can't get it right. Any help would be appreciated. Thanks.

 

My code so far:

Public Class Form1

    Private x As Integer
    Private y As Integer
    Private r As Integer
    Private distance As Integer = 5
    Private blackPen As New Pen(Color.Red, 1)
    Private g As Graphics

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        g = Me.CreateGraphics()
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles Me.Paint   //the drawing of Cartesian Plane
        e.Graphics.FillRectangle(Brushes.White, New Rectangle(300, 10, 500, 491))
        e.Graphics.DrawLine(Pens.Black, New Point(555, 10), New Point(555, 500))
        e.Graphics.DrawLine(Pens.Black, New Point(300, 250), New Point(800, 250))

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.TextLength <> 0 And TextBox2.TextLength <> 0 And TextBox3.TextLength <> 0 Then
            Click = True
            g.Clear(DefaultBackColor)
            g.FillRectangle(Brushes.White, New Rectangle(300, 10, 500, 491))
            g.DrawLine(Pens.Black, New Point(555, 10), New Point(555, 500))
            g.DrawLine(Pens.Black, New Point(300, 250), New Point(800, 250))
            x = CType(TextBox1.Text, Integer) * distance
            y = CType(TextBox2.Text, Integer) * distance
            r = CType(TextBox3.Text, Integer) * distance
            g.FillEllipse(Brushes.Black, x, y, 7, 7)
            g.DrawEllipse(Pens.Black, x, y, r, r)

        Else
            MessageBox.Show("Please Complete All Fields Before Plotting!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End If
    End Sub
End Class