0
votes

Hi sorry for the confusing title.

I'm trying to make a race track using points. I want to draw 3 rectangles which form my roads. However I don't want these rectangles to overlap, I want to leave an empty space between them to place my corners (triangles) meaning they only intersect at a single point. Since the roads have a common width I know the width of the rectangles.

enter image description here

I know the coordinates of the points A, B and C and therefore their length and the angles between them. From this I think I can say that the angles of the yellow triangle are the same as those of the outer triangle. From there I can work out the lengths of the sides of the blue triangles. However I don't know how to find the coordinates of the points of the blue triangles or the length of the sides of the yellow triangle and therefore the rectangles.

2
Thank you for the feedback. I have edited my answer to make it clearer. - S. O' Neill

2 Answers

1
votes

This is an X-Y problem (asking us how to accomplish X because you think it would help you solve a problem Y better solved another way), but luckily you gave us Y so I can just answer that.

What you should do is find the lines that are the edges of the roads, figure out where they intersect, and proceed to calculate everything else from that.

First, given 2 points P and Q, we can write down the line between them in parameterized form as f(t) = P + t(Q - P). Note that Q - P = v is the vector representing the direction of the line.

Second, given a vector v = (x_v, y_v) the vector (y_v, -x_v) is at right angles to it. Divide by its length sqrt(x_v**2 + y_v**2) and you have a unit vector at right angles to the first. Project P and Q a distance d along this vector, and you've got 2 points on a parallel line at distance d from your original line.

There are two such parallel lines. Given a point on the line and a point off of the line, the sign of the dot product of your normal vector with the vector between those two lines tells you whether you've found the parallel line on the same side as the other, or on the opposite side.

You just need to figure out where they intersect. But figuring out where lines P1 + t*v1 and P2 + s*v2 intersect can be done by setting up 2 equations in 2 variables and solving that. Which calculation you can carry out.

And now you have sufficient information to calculate the edges of the roads, which edges are inside, and every intersection in your diagram. Which lets you figure out anything else that you need.

0
votes

Slightly different approach with a bit of trigonometry:

Define vectors

 b = B - A
 c =  C - A
 uB = Normalized(b)
 uC = Normalized(c)
 angle 
 Alpha = atan2(CrossProduct(b, c), DotProduct(b,c))
 HalfA  = Alpha / 2 
 HalfW = Width / 2
 uB_Perp = (-uB.Y, ub.X)  //unit vector, perpendicular to b

 //now calculate points:
 P1 = A + HalfW * (uB * ctg(HalfA) + uB_Perp)  //outer blue triangle vertice
 P2 = A + HalfW * (uB * ctg(HalfA) - uB_Perp)  //inner blue triangle vertice, lies on bisector

(I did not consider extra case of too large width)