dan_e6

10-20-2005, 06:07 AM

i know how to draw lines but how do you draw lines at an angle from another line?

for example: if i have a line that is horizontally straight, and i want to draw a line that is 70 degrees going clockwise from that line how would i do it ?

NEOLLE

10-20-2005, 06:44 AM

i know how to draw lines but how do you draw lines at an angle from another line?

for example: if i have a line that is horizontally straight, and i want to draw a line that is 70 degrees going clockwise from that line how would i do it ?

Hello Dan,

You've got to have reference coodinates to do this. Search it on Analytic Geometry. ;)

dan_e6

10-20-2005, 07:46 AM

i did a search on the forums for that and turned up a result where someone was making a clock and moving the hour hand using a line and angles. which is what i want. the code was short, but i didnt understand it (lost the link..) im not very good with trig! :(

i just want to be able to say "add this many degrees to the X2,Y2 coords of this line and draw the new line"

Diurnal

10-20-2005, 11:22 AM

The trig functions included in VB use radians for an input. You can convert degrees to radians with:

Radians = [Angle in Degrees] * pi / 180 Degrees

Figure out the Sin() and the Cosine() of the angle and miltiply that by the length of each axis on your graph. To understand more how these functions work and can be applied mathematically, see Dr. Math (http://mathforum.org/dr.math/faq/formulas/faq.ag2.html#twolines). The forum hosts tons of answers to any (well, almost...) mathamatical problem.

You must define a starting point for your drawing. I will assume you can use a graph. Making a clock would be the same. Here is an example of drawing a graph onto the center of a form for a canvas. The angled line then starts at the center and is drawn onto the graph:

'Usefull link:

'http://mathforum.org/dr.math/faq/formulas/faq.ag2.html#twolines

Option Explicit

Private Sub Form_Load()

'Set persistant graphics.

Me.AutoRedraw = True

End Sub

Private Sub Form_Click()

Const pi As Double = 3.1416

Dim lAngle As Long

'Clear the canvas (form).

Me.Cls

'Draw a center graph.

Me.Line (Me.ScaleLeft, Me.ScaleHeight \ 2)-(Me.ScaleWidth, Me.ScaleHeight \ 2)

Me.Line (Me.ScaleWidth \ 2, Me.ScaleTop \ 2)-(Me.ScaleWidth \ 2, Me.ScaleHeight)

'Draw line from the center of the graph.

lAngle = 70

Me.Line (Me.ScaleWidth \ 2, Me.ScaleHeight \ 2)- _

(Me.ScaleWidth \ 2 + Cos(lAngle * pi / 180) * Me.ScaleWidth \ 2, _

Me.ScaleHeight \ 2 - Sin(lAngle * pi / 180) * Me.ScaleHeight \ 2), vbRed

End Sub

I hope this can get you started.