Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing Wind Direction.

Status
Not open for further replies.

Eldaria

Programmer
Sep 20, 2001
123
NL
I'm working on making a program that is going to show wind direction.
I have made a circle and a line that goes from the middle and to the edge of the circle.

I was never any good in math class when it came to cricles, so how do I calculate the rotation of the line? the middle is fixed, but I need to be able to rotate the line 360 degrees, so 180 would be showing down, and 0 pointing up, etc...
 
To use the following code you must have a form called form1, a shape called shape1 and set to circle, and a line called line1.



Private Sub Form_Load()
PositionLine (90) 'Change the 90 to rotate the line
End Sub

Private Sub PositionLine(degree As Integer)
Dim radius As Long
Dim CenterX As Long
Dim CenterY As Long
Dim OneDegree As Double
Dim x As Double
Dim y As Long
Dim l As Integer
degree = degree + 90
l = 1
Do While degree > 180
If l = 1 Then
l = -1
Else
l = 1
End If
degree = degree - 360
Loop

If degree < 0 Then degree = -degree

radius = 1000
CenterX = Form1.Width / 2
CenterY = Form1.Height / 2
Shape1.Width = radius * 2
Shape1.Height = radius * 2
Shape1.Left = CenterX - Shape1.Width / 2
Shape1.Top = CenterY - Shape1.Height / 2
Line1.X1 = CenterX
Line1.Y1 = CenterY
OneDegree = (radius / 90)
x = CenterX + radius - degree * OneDegree
y = CenterY - (Sqr(radius * radius - (CenterX - x) * (CenterX - x))) * l
Line1.X2 = x
Line1.Y2 = y

End Sub


 
Are you looking for the point on the circumference of the circle that is the end point of the line OR are you asking how to compute the angle that the line makes with the horizontal (or vertical?)
 
Here's a sample on how to make a line from the center of a circle to the edge using minutes 0 - 60 to represent the location to insert the line. Just modify to your needs.

Option Explicit

Private Sub Command1_Click()
Dim intMinutes As Integer
intMinutes = 30
Dim x As Integer, y As Integer
Dim rad As Integer
x = 2000
y = 2000
rad = 800
Me.Circle (x, y), rad
DrawHand x, y, intMinutes, rad
End Sub
Public Sub DrawHand(intX As Integer, intY As Integer, intValue As Integer, rad As Integer)
Dim x As Integer, y As Integer
Const pi = 3.14159
x = rad * Sin((intValue * pi) / 30)
y = rad * Cos((intValue * pi) / 30)
Me.Line (intX, intY)-(intX + x, intY - y)
End Sub
 
Use an empty form with a command button (cmd1):

Private Sub cmd1_Click()
Dim x as Integer 'start point x co-ord
Dim y as Integer 'start point y co-ord
Dim a as Integer 'end point x co-ord
Dim b as Integer 'end point y co-ord
Dim c as Single 'angle as radians
Dim d as Single 'input angle in degrees
d = InputBox(&quot;angle&quot;)
c = d * 3.142 / 180
x = 5000
y = 5000
b = -1000 * Cos(c)
a = 1000 * Sin(c)
Me.Line (x, y)-Step(a, b)
End Sub


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top