简体   繁体   中英

Calculate the angle of two connected line segments based on a randomly position point

I have a 3 coordinates (A, B, C) which form two connected line segments.

I want to calculate the angle of the line segment based upon a random point that can fall either side of the line segments.

For example, if the random point was D, I would want to calculate the green angle, or if the random point was E, I would want to calculate the red angle.

I don't mind what programming language the solution is written in, but Python or Javascript would be preferred.

在此处输入图片说明

Assuming that the points use cartesian coordinates (x,y) . Given two points A & C, angle made with x-axis is given by tan-inverse of (slope)

theta_ac = Math.atan((ya-yc)/(xa-xc))

Similarly once theta_bc is computed, the angle is given by theta_bc - theta_ac

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM