I have this issue and I've been trying to solve this for hours but wasn't able to find a solution which works in all circumstances. I feel sad because this seems like a simple trigonometry problem. I hope you can help me find a solution to this.
What I try to calculate are essentially the red points (I'll call them P
later on) at the end of the red lines in this picture:
The red lines are just for reference and everything is drawn by hand and might therefor not be to scale.
I have a list of coordinates (black points) building a route (black line), for example:
[ (12, 9), (13,10), (13,11) ]
In order to find the red points I iterate through the route and look at 3 consecutive points at a time. Where the two edges connect (i.e. the middle point) is a place where the red line starts.
The rules are as follows:
- given are 3 points:
A
for after,B
for before,C
for current (shorthand for each triangle and their meaning in the route) - given is
j
, the length of the red line - the angle for BCP and ACP must be the same
- if multiple answers are possible, choose the one which 'goes with the flow' and is further away from the corner points for it to form a "Y" shape as indicated by the red line
- calculate the coordinates for each
P
as(y,x)
To illustrate the issue I made following diagram of just one such iteration:
(The y-axis on the grid is reversed in this one, but never mind)
What I already managed to do:
- Given the points A,B and C, I can calculate the length of the edges as well as the angle
ACB=135°
. For this I used this function:
def angle_between(previous, current, next):
a = math.sqrt((next[0]-previous[0])**2 + (next[1]-previous[1])**2)
b = math.sqrt((current[0]-previous[0])**2 + (current[1]-previous[1])**2)
c = math.sqrt((current[0]-next[0])**2 + (current[1]-next[1])**2)
angle_alpha = math.acos((b**2 + c**2 - a**2)/(2*b*c))
return round(math.degrees(angle_alpha), 2)
- I then can calculate
PCB=180-(ACB/2)=112.5°
.
So I know everything I should need to know except the resulting coordinates of P.
I tried to calculate them with the following code but I didn't get the results I expected:
P = (C[0] + j*math.cos(PCB_rad) , C[1] + j*math.sin(PCB_rad))
Can someone please help me? Maths is not my strength it seems.. Thx!
Best Answer
Edit
Here we post the explicit formula which can be used to another lanugage.
According to the Angle bisector theorem, https://en.wikipedia.org/wiki/Angle_bisector_theorem
we can calculate the point
d
on theab
edge and setdir=c-d
as the direction vector fromc
top
p=c+length*Normalize[dir]
, it can be illustrated as below.Original