I have two lines that mean four points(x,y) on picturebox.
i have allready find out then point (x,y) of intersection between them.
Now i want to determine the angle between them and then want draw a line which should pass though the intersection point and should be bisect this angle. pl help me out..
Let (x1,y1) and (x2,y2) be the two points of the first line.
Get the distance between the two.
Now make a horizontal line passing from the (x1,y1) & drop a perpendicular from (x2,y2) on it.
By this you get the two distances, (x1,y1) - (x2,y2)
and (x1,y1) - (xc,yc) where (xc,yc) is the coordinate of the point that you get by intersection of the perpendicular and the horizontal line.
as we know that cosine(x) = distance (x1,y1) - (xc,yc) / distance (x1,y1) - (x2,y2) in this case and thus you could easily get the angle between horizontal and the line.
Similiarly, perform same operation on another line as well . Add the two and you get the actual angle between the two lines.
Now you could find the half of that angle and draw a line at a given angle.
Let (x1,y1) and (x2,y2) be the two points of the first line.
Let (x3,y3) and (x4,y4) be the two points of the second line.
Let (x0,y0) be the intersection between them
slope for the intercept line
m = (m1 + m2)/2
m = {[(y2-y1)/(x2-x1)] + [(y4-y3)/(x4-x3)]} / 2
since y = mx + b
b = y0 - mX0
and you will get the line equation as
y = mx + (y0 - mX0)
where m= {[(y2-y1)/(x2-x1)] + [(y4-y3)/(x4-x3)]} / 2
your solution doe'nt work in case m =(m1+m2)/2 comes out zero as well as in m1 or m2 is zero.
ashutosh9910 your solution i couldn't understand what you want to say. if i want to determine only angle between them then i can use vector calculation but here i want to draw a line which should pass thought intersection as well as should bisect this two lines.
By the way, the way I do is general case. If you say one slope is 0 (x-axis), the other one must be y-axis which is infinite slope. In your code, you have to take a special case for this
Thanks for yur efforts.... but my problem not solved yet. i have tryied your solution but in all cases i am not getting right results.Now i want to give you my whole problem might be then it's easier to understand.
i am trying to give user to draw pipes, i.e means two parallel lines and a center line when user click and drag the mouse. which i have completed and it's happeing. After that user can set dia1 and dia2 of selected pipe in picturebox. Now i want to give user facility to select two pipes in picturebox and then click a button "Connect", and my works start in background in which i have to extend or trim center lines as well as outer dia lins of two pipes. I have completed connection of center lines but for outer lines connection i am getting problem. So i thought about above solution, in which i would determine the bisection line eq. and then try to find out intersection with outer dia pipes. But i am not getting desired results. I thing Atn function of vb not producing desired results.
what i had......
1. center points quardinets i.e. x1,y1 and x2, y2 to each pipes
2. outer lines quardinates i.e. xx1,yy1 and xx2,yy2 and xxx1,yyy1 and xxx2,yyy2.
i have same types of above information two objects
Now i want to determine xc,yc and xu,yu and xv,yv all three cross-section so that i could join them. xc,yc i had determine already..
Dim a As Single
Dim b As Single
Dim ang As Single
Dim M_angle As Single
Dim IsVertical As Boolean
Dim dxx1 As Single
Dim dxx2 As Single
Dim dyy1 As Single
Dim dyy2 As Single
'------------------------------------------------------------------
a = angle_Lines(obj_1, X1, Y1)
b = angle_Lines(obj_2, X1, Y1)
ang = (a + b) / 2
If ang < 90 Then
ang = -ang
ElseIf ang < 180 Then
ang = 180 - ang
ElseIf ang < 270 Then
ang = -(ang - 180)
Else
ang = ang - 180
End If
M = Tan(Rad(ang))
'------------------------------------------------------------------
' ' Now we have X,Y and m so we have to determine only C
If IsVertical Then
X2 = X1
Y2 = Y1 + 10
Else
C = Y1 - M * X1
' assume x= x-5
X2 = X1 + 10
Y2 = M * X2 + C
End If
Private Function angle_Lines(obj As vbdObject, x As Single, y As Single) As Single
Dim dx As Double
Dim DY As Double
Dim temp As Single
Dim a_mod As Single
If obj.x(1) = x Then
dx = obj.x(2) - x
Else
dx = obj.x(1) - x
End If
If obj.y(1) = y Then
DY = y - obj.y(2)
Else
DY = y - obj.y(1)
End If
If dx > 0 And DY = 0 Then
temp = 0
ElseIf dx > 0 And DY > 0 Then
temp = Atn(Abs(DY / dx))
ElseIf dx = 0 And DY > 0 Then
temp = PI / 2
ElseIf dx < 0 And DY > 0 Then
temp = PI - Atn(Abs(DY / dx))
ElseIf dx < 0 And DY = 0 Then
temp = PI
ElseIf dx < 0 And DY < 0 Then
temp = PI + Atn(Abs(DY / dx))
ElseIf dx = 0 And DY < 0 Then
temp = (3 / 2) * PI
ElseIf dx > 0 And DY < 0 Then
temp = 2 * PI - Atn(Abs(DY / dx))
End If
angle_Lines = Degrees(temp)
End Function
thanks to everyone who supported me....
nikelsh
0
Featured Post
With monday.comâ€™s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.
Get the distance between the two.
Now make a horizontal line passing from the (x1,y1) & drop a perpendicular from (x2,y2) on it.
By this you get the two distances, (x1,y1) - (x2,y2)
and (x1,y1) - (xc,yc) where (xc,yc) is the coordinate of the point that you get by intersection of the perpendicular and the horizontal line.
as we know that cosine(x) = distance (x1,y1) - (xc,yc) / distance (x1,y1) - (x2,y2) in this case and thus you could easily get the angle between horizontal and the line.
Similiarly, perform same operation on another line as well . Add the two and you get the actual angle between the two lines.
Now you could find the half of that angle and draw a line at a given angle.
Bit confusing but i hope you get it.