- Home /
Finding random intersecting line
Okay, so I have kind of a problem.
I have two points (A, B), and I want to find two other Points (C,D) which create a line that intersects the line AB. It doesn't matter where it intersects, aslong as it doesn't touch point A or B (Like a Random generator to create an obstacle). The Points A and B are Vector3(x,y,0), the line is drawn by a LineRenderer. C should be anywhere on the blue circle and D anywhere on the red circle. The Line CD is drawn by a LineRenderer too.
Answer by tormentoarmagedoom · Feb 08, 2020 at 01:11 PM
i would do this:
1- add collider to the AB line, so can be detected by next line.
2 -create a point C at rnadom place, and with a collider bigger than the point be sure it does not touch the line (this means C is not touching A / B).
3 -Then create point D and do the same to detect A B or C
4 -generate the CD line with a collider and detect if is detecting AB line. if not, need to restart from point 3 of this list.
Byee!
Answer by lvjuvan · Feb 08, 2020 at 05:18 PM
Ok, at first thought, I'd say find the angles of the points on the boundary (simple trigonometry) then find the points, so that one point is strictly inside the a-b range and the other is strictly outside outside. The point on the boundary depending on the angle will be r*(cos(x), sin(x)), where r is the circle radius.
Your answer
![](https://koobas.hobune.stream/wayback/20220612222909im_/https://answers.unity.com/themes/thub/images/avi.jpg)