|
-
Nov 18th, 2010, 05:33 PM
#2
Re: Math Problem :[
Hi Skatebone, here's a few things you need to fix:
1. Make Rads a Double rather an Integer, because otherwise it will only range from 0 to 7 which would be a bit odd for a clock!
2. To draw an angled line, you set the height to the Sin of the angle and the width to the Cos.
I've marked these points in your code below:
 Originally Posted by Skatebone
Code:
Public Class Form1
Dim Pt1 As Point = New Point(100, 100)
Dim Pt2 As Point = New Point(100, 75)
Dim Pt3 As Point = New Point(125, 100)
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.FillEllipse(Brushes.White, 75, 75, 50, 50)
e.Graphics.DrawEllipse(Pens.Black, 75, 75, 50, 50)
e.Graphics.DrawLine(Pens.Black, Pt1, Pt2)
'Variable triangle
e.Graphics.DrawLine(Pens.Black, Pt1, Vary(90))
End Sub
Private Function Vary(ByVal variable As Integer) As Point
Dim width As Integer
Dim height As Integer = 0
Dim Rads As Double = (variable / 180) * 3.146
width = Cint(25 * Math.Cos(Rads)
height = Cint(25 * Math.Sin(Rads))
Dim tmpPt As Point = New Point(100 - width, 100 + height)
Return tmpPt
End Function
End Class
You should find it works with those changes. I think it's a good idea to work with Option Strict On, especially with Math(s), which is why I added the Cint in the code.
BB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|