I am trying to find the vector or angle in order to calculate the points where two "thick" lines would intersect. The end goal is to draw simple flat planes for a thick line renderer.
Although I'm using Unity and am working with Vector3, for my purposes, assume the Z-value is always 0. This is a 2d problem. It is not a Unity specific problem and I'm not sure why I'm having a hard time finding a solution that I can understand. Getting points for drawing a "thick" line is surely not new. But for the life of me, I can't find a solution.
The closest I've come is figuring out points along the line perpendicular to the one I want. I know that this is the "bounce" line. In other words, with 3 points, I can get the vector for the line that represents the side of a billiard ball table assuming the middle point is the point of impact with the side of the table. What I want is the vector perpendicular to that side. I worked out the code below according to the post here: https://answers.unity.com/questions/1503945/how-to-get-the-cross-direction-for-3-points.html However, it's not working and I don't understand matrix math or Vector API's enough to figure out how to rotate my points, etc. My math, vector, and trigonometry skills are just not up to this challenge.
I've included an image from in Unity showing what I can get. You can see the blue line which is so close to what I want. I can get points C1 and C2 that are an arbitrary distance (thickness) out from the point of impact. They just need to be rotated 90 degrees to give me D1 and D2. Then I can get the points to use in the drawing api.
The second image illustrates the actual information I'm trying to get. If I can just get the points, I can work on the custom mesh rendering myself.
The code below should be ready to display instantly once added to an empty GameObject in Unity in case that helps.
Maybe I'm trying to do this all wrong and need to instead start with two parallel lines set "thickness" apart from the points comprising the line and calculate the intersect points of those? Any feedback, not to mention an actual solution, would be greatly appreciated.
using UnityEngine;
public class ThickLineRenderer : MonoBehaviour {
private void OnDrawGizmos() {
Vector3[] points = new Vector3[] { new Vector3(-1, -1), new Vector3(0, 0), new Vector3(-1, 1) };
Vector3 p1 = points[0];
Vector3 p2 = points[1];
Vector3 p3 = points[2];
Gizmos.color = Color.white;
Gizmos.DrawLine(p1, p2);
Gizmos.DrawLine(p2, p3);
Vector3 n1 = (p2 - p1).normalized;
Vector3 n2 = (p3 - p2).normalized;
Vector3 n = (n1 + n2).normalized;
Vector3 d = p2 + n;
Vector3 d2 = p2 - n;
Gizmos.color = Color.blue;
Gizmos.DrawLine(p2, d);
Gizmos.DrawLine(p2, d2);
}
}