Hello all, I'm working on a coding project where I'm trying to determine the deviation in degrees from a line X = B.x2 at a point B(x2,y2) by another line formed by bisection of the angle ABC of A(x1,y1), B(x2,y2) and C(x3,y3) : check the image below, it's more clear:
with the help of a friend I've managed to write some pseudo code and a sample python code for the case when B is always above A and C as follows:
English pseudo code in reference to the image above:
sample python code:
I'd really appreciate if someone could check if my logic is accurate and also how would I handle the case where B is below A and C where theta could lie in either quadrant 1(0-90 degrees) or quadrant 2(90-180 degrees)... only these two cases need to be handled.
with the help of a friend I've managed to write some pseudo code and a sample python code for the case when B is always above A and C as follows:
English pseudo code in reference to the image above:
Code:
if B is above A and C then:
BA|x| = B.x - A.x //magnitude of x
BA|y| = B.y - A.y // " y
BC|x| = B.x - C.x // " x
BC|y| = B.y - C.y // " y
angle_alpha = tan^-1( BAy / BAx )) // angle between AB and line y= B.y
angle_beta = tan^-1( BCy / BCx )) // angle between AC and line y= B.y
angle_gamma = 90 - angle_alpha //angle between line BA and line x=B.x
angle_delta = 90 - angle_beta //angle between line BC and line x=B.x
angle_omega = angle_gamma + angle_delta //angle between BA and BC
bisected_angle = angle_omega/2 //angle between Z and BA or BC
// next we determine the quadrant our bisector lies in as the points in some
//instances Z can be on the left of Q
if angle_delta is greater than angle_gamma then:
our_quadrant = fourth //// between 270 && 360 degrees
angle_theta = bisected_angle - angle_delta
otherwise:
our_quadrant = third // between 180 && 270 degrees4
angle_theta = bisected_angle - angle_gamma
we return our quadrant & angle_theta
sample python code:
Code:
import math
def error_angle(A, B, C):
# Calculate BA and BC vectors
BAx = B[0] - A[0]
BAy = B[1] - A[1]
BCx = B[0] - C[0]
BCy = B[1] - C[1]
# Calculate angles alpha and beta
angle_alpha = math.degrees(math.atan(BAy/ BAx))
angle_beta = math.degrees(math.atan(BCy/ BCx))
# Calculate angles gamma and delta
angle_gamma = 90 - angle_alpha
angle_delta = 90 - angle_beta
# Calculate angle omega (angle between BA and BC)
angle_omega = angle_gamma + angle_delta
# Calculate the bisected angle
bisected_angle = angle_omega / 2
# Determine the quadrant
if angle_delta > angle_gamma:
our_quadrant = "fourth"
angle_theta = bisected_angle - angle_delta
else:
our_quadrant = "third"
angle_theta = bisected_angle - angle_gamma
return our_quadrant, angle_theta
# Example usage
A = (2, 4)
B = (5, 8)
C = (8, 2)
quadrant, angle = error_angle(A, B, C)
print("Quadrant:", quadrant)
print("Angle:", angle)
I'd really appreciate if someone could check if my logic is accurate and also how would I handle the case where B is below A and C where theta could lie in either quadrant 1(0-90 degrees) or quadrant 2(90-180 degrees)... only these two cases need to be handled.
Last edited: