-
I have drawn a line and i need to find the perpendicular line to it in order to put an a arrow head on the line
the line that g ets the arrow head may be point in one of 360 degrees so if you know how to do that i wouls appreciate it
other wise i need to figur out how to get the points to draw a perpendicular line to ANY line.
thanks guys
-
Cool Problam man!!! :)
As you said it's a math question.
When you drow a line you got 4 positions...2 X and 2 Y.
Lets say a line starts a "A" and ends at "B": You'll have Xa and Ya in one hand and Xb and Yb in the other, Now you can calculate their Tang or Sin Or Cos, whatever...
The lenght you can calculate with Pitagoras: (AB)^2=x^2 +y^2
Now you got a math prob so what's the problem? :)
Edy
-
Hi.
You can use Line method to draw:
Code:
Line (0, 1000)-(2000, 1000) 'Horizontal
Line (1000, 0)-(1000, 1000) 'Vertical
Larisa
-
thasnk but the answer is still unanswered I know how to get the length and stuff but that still doesn't get me the additional points i need to give the line an arrow like point which is my main objective
-
Yes. I see
I think you want an arrow like this: --|>
(OK, it's not a perfect representation, but you can get the gist).
'Your across line
Line(1000, 1000)-(2000, 1000)
'Then the perpendicular vertical line
Line(2000, 900)-(2000, 1100)
What Edwardo was saying is that the end of the point of the line has to be a triangle. (You can't use Pythagoras's Theorem because it only applies to right-angled triangles). So you've got to make two more lines:
'Line from the top of the perpendicular line to
'the tip of the arrow
Line(2000, 900)-(2200, 1000)
'Line from the bottom of the perpendicular line to
'the tip of the arrow
Line(2000, 1100)-(2200, 1000)
It works on my computer...
Hope I've been helpful (at least I've tried) :)
-
Try this
Code:
Private Sub DrawArrow(Shaft As Line, TipLeft As Line, TipRight As Line, TipBase As Line, TipLength As Single, TipWidth As Single)
Dim sngTipLengthAsFraction As Single
Dim sngTipWidthAsFraction As Single
Dim sngShaftLength As Single
sngShaftLength = Sqr((Shaft.X1 - Shaft.X2) ^ 2 + (Shaft.Y1 - Shaft.Y2) ^ 2)
sngTipLengthAsFraction = TipLength / sngShaftLength
sngTipWidthAsFraction = TipWidth / sngShaftLength
TipBase.X1 = Shaft.X1 + sngTipLengthAsFraction * (Shaft.X2 - Shaft.X1) + sngTipWidthAsFraction * (Shaft.Y1 - Shaft.Y2)
TipBase.Y1 = Shaft.Y1 + sngTipLengthAsFraction * (Shaft.Y2 - Shaft.Y1) + sngTipWidthAsFraction * (Shaft.X2 - Shaft.X1)
TipBase.X2 = Shaft.X1 + sngTipLengthAsFraction * (Shaft.X2 - Shaft.X1) - sngTipWidthAsFraction * (Shaft.Y1 - Shaft.Y2)
TipBase.Y2 = Shaft.Y1 + sngTipLengthAsFraction * (Shaft.Y2 - Shaft.Y1) - sngTipWidthAsFraction * (Shaft.X2 - Shaft.X1)
TipRight.X1 = Shaft.X1
TipRight.Y1 = Shaft.Y1
TipRight.X2 = TipBase.X2
TipRight.Y2 = TipBase.Y2
TipLeft.X1 = Shaft.X1
TipLeft.Y1 = Shaft.Y1
TipLeft.X2 = TipBase.X1
TipLeft.Y2 = TipBase.Y1
End Sub
this procedure will draw your arrow, where shaft is the line you want to base your arrow on, tipleft,tipright and tipbase are the lines which will form your arrow, TipLength is the height of the triangle at the end and tipwidth is the width of it's base.
Hope this helps.
-
No one is answering my question. You are trying but perhaps you dont understand what i am asking of you. the line that needs the arrow is virtually a random line, i never know anything other than the end points of the line. that is all i know. NOTHING ELSE. and i need to put the arrow head on it. AGAIN it is a RANDOM line sometimes it could be
pic1.line (12,2)-(24,6)
or it could be
pic1.line (53,78)-(1,3)
I never know , more than those two points. It is from ONLY those two points that i need to figure out how to fashion an arrow head on the point
thanks for trying though :)
please if anyone has an answer now i would be much obliged
-
Did you try Sam Finch's code? It works just fine, you just have to adjust it a bit to get the arrow at the other end of the line. You'll also need four lines: one for the main line and the other three for the arrow's triangle. Don't be afraid to play around with the code, you'll only get out of it what you put in to it.
-
ok then how do i get TipLeft As Line, TipRight As Line, TipBase As Line, TipLength As Single, TipWidth As Single?
if i get that then i will try.
-
Instead of use the line method use a Line object (added from the ToolBox). Make the Line object into a control array, done by setting its Index property to 0. Now when you load your project do the following:
Code:
Private Sub Form_Load()
Load Line1(1)
Load Line1(2)
Load Line1(3)
End Sub
Now call the DrawArrow procedure in the function where you randomally generate the main line as follows:
Code:
Call DrawArrow(Line1(0), Line1(1), Line1(2), Line1(3), 200, 100)
Line1(0).Visible = True
Line1(1).Visible = True
Line1(2).Visible = True
Line1(3).Visible = True
The parameters for DrawArrow are as follows:
Shaft As Line
- The main line that you're drawing.
Because the arrow head is a triangle you need three lines to create it.
TipLeft As Line
- The left side of the Isoceles triangle for the arrow head.
TipRight As Line
- The right side of the Isoceles triangle for the arrow head.
TipBase As Line
- The base (the perpendicular line to the main line) of the arrow head triangle.
TipLength As Single
- How far down the main line from the tip of the main line that you want the arrow head's base to be.
TipWidth As Single
- How wide to make the base of the arrow head (ie. the perpendicular line to the main line).
To elaborate further, three of the four lines you pass in
are used for the arrow head and are positioned by the procedure, you specify the dimensions of the triangle through the TipLength and TipWidth parameters.
And just to make it really easy, here's the modified procedure to draw the arrow head at the other end of the line:
Code:
Private Sub DrawArrow(Shaft As Line, TipLeft As Line, TipRight As Line, TipBase As Line, TipLength As Single, TipWidth As Single)
Dim sngTipLengthAsFraction As Single
Dim sngTipWidthAsFraction As Single
Dim sngShaftLength As Single
sngShaftLength = Sqr((Shaft.X1 - Shaft.X2) ^ 2 + (Shaft.Y1 - Shaft.Y2) ^ 2)
sngTipLengthAsFraction = TipLength / sngShaftLength
sngTipWidthAsFraction = TipWidth / sngShaftLength
TipBase.X1 = Shaft.X2 - sngTipLengthAsFraction * (Shaft.X2 - Shaft.X1) + sngTipWidthAsFraction * (Shaft.Y1 - Shaft.Y2)
TipBase.Y1 = Shaft.Y2 - sngTipLengthAsFraction * (Shaft.Y2 - Shaft.Y1) + sngTipWidthAsFraction * (Shaft.X2 - Shaft.X1)
TipBase.X2 = Shaft.X2 - sngTipLengthAsFraction * (Shaft.X2 - Shaft.X1) - sngTipWidthAsFraction * (Shaft.Y1 - Shaft.Y2)
TipBase.Y2 = Shaft.Y2 - sngTipLengthAsFraction * (Shaft.Y2 - Shaft.Y1) - sngTipWidthAsFraction * (Shaft.X2 - Shaft.X1)
TipRight.X1 = Shaft.X2
TipRight.Y1 = Shaft.Y2
TipRight.X2 = TipBase.X2
TipRight.Y2 = TipBase.Y2
TipLeft.X1 = Shaft.X2
TipLeft.Y1 = Shaft.Y2
TipLeft.X2 = TipBase.X1
TipLeft.Y2 = TipBase.Y1
End Sub
There you go, hope it's meets your needs now, let me know either way.
Later.
-
great it worked!!! the key was using that line object rather than using the line. Thanks alot though. it seems so obvious now.
thanks again