Bisection line of a angle

Posted on 2004-11-02
Last Modified: 2008-02-01
Dear all,

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..


Question by:nikelsh
    LVL 8

    Expert Comment

    by:Ashutosh Vyas
    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.

    Bit confusing but i hope you get it.

    LVL 26

    Expert Comment

    I',m not sure my logic is right

    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

    LVL 26

    Expert Comment

    Of course the second inteception line will be

    ms * m = -1

    and you will get the slope of the second line (ms)

    and use the above to find the second equation
    LVL 1

    Author Comment

    hi EDDYKT,

    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.

    waiting for ans

    LVL 26

    Expert Comment

    >>your solution doe'nt work in case m =(m1+m2)/2 comes out zero as well as in m1 or m2 is zero.

    the both lines are parallel to x-axis and should has no intercept pt

    Am i missing somehting?

    in my case

    m1 = (y2-y1)/(x2-x1)
    m2 = (y4-y3)/(x4-x3)
    LVL 26

    Expert Comment

    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
    LVL 1

    Author Comment

    Hi EDDYKT,

    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..

    could you help me to find out this.......


    LVL 26

    Expert Comment

    see me your code and see what's wrong
    LVL 1

    Accepted Solution

    it' ans is

    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)
        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
        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
            dx = obj.x(1) - x
        End If
        If obj.y(1) = y Then
            DY = y - obj.y(2)
            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....


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Learn The Basics of Ethical Hacking & Pen Testing

    Computer and network security is one of the fastest growing and most essential industries in technology, meaning companies will pay big bucks for ethical hackers. This is the perfect course to leap into this lucrative career, learning how to use ethical hacking to reveal ...

    Suggested Solutions

    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now