Results 1 to 6 of 6

Thread: arrows

  1. #1

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    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
    retired member. Thanks for everything

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    use the anglebyoffset function
    http://forums.vb-world.net/showthrea...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.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197

    I fell really stupid asking this but...

    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?
    Last edited by markman; Mar 6th, 2001 at 04:39 PM.
    retired member. Thanks for everything

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
        |
        |
        |
        |
        |
        |
        |
    \   |    /
     \  |   / 
      \ |a/ l
       \|/
    a is the angleoffset between and l is the length the arrow head lines
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    Ok, so far:
    Code:
    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?
    retired member. Thanks for everything

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width