PDA

Click to See Complete Forum and Search --> : arrows


markman
Mar 5th, 2001, 02:51 PM
I am trying to make a funciton to draw an arrow on the tip of any line.

All I need to know is how to find the coordinates of a point n away from the end of the line if I am given x1,x2,y1,and y2. The line should be able to vary in slope and position

kedaman
Mar 5th, 2001, 06:35 PM
use the anglebyoffset function
http://forums.vb-world.net/showthread.php?s=&threadid=58789
i posted there
to get the direction the line is pointing from, and draw the lines from the head point to
x=cos(angle+angleoffset)*length
y=sin(angle+angleoffset)*length
and
x=cos(angle-angleoffset)*length
y=sin(angle-angleoffset)*length
where angleoffset is the angle between the line and arrowlines, and length is the length of these lines.

markman
Mar 6th, 2001, 03:10 PM
I am guessing that you got the variable angel from your finction but where did you get the angle offset variable? Is there some geometry that I dont know or something? Also, you said that length is the length of these lines.What lines?

kedaman
Mar 6th, 2001, 03:52 PM
|
|
|
|
|
|
|
\ | /
\ | /
\ |a/ l
\|/

a is the angleoffset between and l is the length the arrow head lines

markman
Mar 6th, 2001, 04:05 PM
Ok, so far:

Const ab = 100

Private Sub Command1_Click()
With Line1
Line2.X1 = .X2 'set the beginnings all equal to the end
Line2.Y1 = .Y2
Line3.X1 = .X2
Line3.Y1 = .Y2
Line2.X2 = Cos(AngleByOffset(.X2, .Y2) + FindAngleOffset(ab, FindLength(Line2.X1, Line2.X2, Line2.Y1, Line2.Y2))) * FindLength(Line2.X1, Line2.X2, Line2.Y1, Line2.Y2) 'what i think you said
Line2.Y2 = Sin(AngleByOffset(.X2, .Y2) + FindAngleOffset(ab, FindLength(Line2.X1, Line2.X2, Line2.Y1, Line2.Y2))) * FindLength(Line2.X1, Line2.X2, Line2.Y1, Line2.Y2)
Line3.X2 = Cos(AngleByOffset(.X2, .Y2) - FindAngleOffset(ab, FindLength(Line3.X1, Line3.X2, Line3.Y1, Line3.Y2))) * FindLength(Line3.X1, Line3.X2, Line3.Y1, Line3.Y2)
Line3.Y2 = Sin(AngleByOffset(.X2, .Y2) - FindAngleOffset(ab, FindLength(Line3.X1, Line3.X2, Line3.Y1, Line3.Y2))) * FindLength(Line3.X1, Line3.X2, Line3.Y1, Line3.Y2)
End With
End Sub

Function FindAngleOffset(arrowBase As Integer, LengthofTipSide As Double)
FindAngleOffset = (arrowBase / 2) / Sin(LengthofTipSide)
End Function

Function FindLength(X1 As Double, X2 As Double, Y1 As Double, Y2 As Double)
FindLength = Sqr(((X1 - X2) ^ 2) - ((Y1 - Y2) ^ 2)) 'distance formula
End Function

Function AngleByOffset(offsetX As Double, offsetY As Double) As Double
If offsetX Then
AngleByOffset = Atn(offsetY / offsetX) - (offsetX > 0) * 3.14159265358979
Else
AngleByOffset = 1.5707963267949 + (offsetY > 0) * 3.14159265358979
End If
End Function


.....But it doesnt work. Is there anything I did wrong?

kedaman
Mar 6th, 2001, 05:05 PM
Some programming etics: store return values instead of calling same function with same parameters.

I have no idea why you would need to calculate the angleoffset, it's suppose to be constant, you could use a fixed arrowheadline length also, but you have the same length as the arrow base itself, is this nessesary?

i spotted the error though, x and y are not absolute but relative to the arrowhead, add the arrowhead coordinate to get the absolute coordinate