void Update() { var a = A.position.xz(); var b = B.position.xz(); DebugUtil.DrawLine(a, b); var c = C.position.xz(); Math.ProjectSeg(a, b, c, out var r); DebugUtil.DrawPoint((float2)r); DebugUtil.DrawPoint(a); DebugUtil.DrawPoint(b); DebugUtil.DrawPoint(c); }
void Update() { var p1 = ((float3)A.position).xz; var p2 = ((float3)B.position).xz; var p3 = ((float3)C.position).xz; DebugUtil.DrawLine(p1.ToXxY(), p2.ToXxY()); DebugUtil.DrawCircle(p3, R, StartRot, Rot); var hits = new NativeList <float2>(Allocator.Persistent); IntersectSegCircleSeg(p1, p2, p3, R, NormalizeAngle(StartRot), NormalizeAngle(StartRot + Rot), hits); foreach (var hit in hits) { DebugUtil.DrawPoint(hit, Color.magenta); } hits.Dispose(); }
void Update() { var p0 = C0.position.xz(); var p1 = C1.position.xz(); var c = C.position.xz(); var p = P.position.xz(); DebugUtil.DrawCircle(p0, R, Color.green); DebugUtil.DrawCircle(p1, R, Color.red); DebugUtil.DrawCircle(c, R); Math.GetOuterTangentRight(p0, p1, R, out var ol0, out var ol1); DebugUtil.DrawLine(ol0, ol1, Color.black); DebugUtil.DrawPoint(ol0, Color.green); DebugUtil.DrawPoint(ol1, Color.red); Math.GetOuterTangentLeft(p0, p1, R, out var or0, out var or1); DebugUtil.DrawLine(or0, or1, Color.white); DebugUtil.DrawPoint(or0, Color.green); DebugUtil.DrawPoint(or1, Color.red); Math.GetInnerTangentRight(p0, p1, R, out var il0, out var il1); DebugUtil.DrawLine(il0, il1, Color.black); DebugUtil.DrawPoint(il0, Color.green); DebugUtil.DrawPoint(il1, Color.red); Math.GetInnerTangentLeft(p0, p1, R, out var ir0, out var ir1); DebugUtil.DrawLine(ir0, ir1, Color.white); DebugUtil.DrawPoint(ir0, Color.green); DebugUtil.DrawPoint(ir1, Color.red); var left = Math.GetTangentLeft(p, c, R); DebugUtil.DrawLine(p, left, Color.white); var right = Math.GetTangentRight(p, c, R); DebugUtil.DrawLine(p, right, Color.black); }
void Update() { var a = ((float3)A.position).xz; var b = ((float3)B.position).xz; var c = ((float3)C.position).xz; var s1 = ((float3)S1.position).xz; var s2 = ((float3)S2.position).xz; var v = ((float3)V.position).xz; DebugUtil.DrawLine(s1, s2, Color.red); Math.CircleFromPoints(a, b, c, out var p, out var r); DebugUtil.DrawCircle((float2)p, (float)r); var ba = a - b; var bc = c - b; var validBacProjection = Math.ProjectSeg(a, c, b, out var bac); if (validBacProjection) { var bbac = bac - b; var bbaca = Math.Angle(bbac); var lba = math.length(ba); var lbc = math.length(bc); float2 shortestEdge; float clearance; if (lba <= lbc) { shortestEdge = ba; clearance = lba; } else { shortestEdge = bc; clearance = lbc; } var angle = Math.Angle(bbac, shortestEdge); var startRot = bbaca + angle; var rot = bbaca - angle - startRot; DebugUtil.DrawCircle(b, clearance, startRot, rot); DebugUtil.DrawCircle(b + (c - 2 * bac + a), clearance, startRot, rot); // todo check all edges crossing traversal zones to find s1, s2 var validBsProjection = Math.ProjectSeg(s1, s2, b, out var bi); clearance = math.min(clearance, math.length(bi - b)); if (validBsProjection) { var s12 = s2 - s1; // The paper says R is delimited by a line parallel to s passing by b. // When cl(a, b, c) == dist(b, a) and dist(b, a) < dist(b, s) this allows // for vertices in R violating definition 3.4: dist(v, s) < cl(a, b, c). // R will be delimited by a line parallel to s with distance cl(a, b, c) // Technially r1 should be at the intersection point with bc, but as bc // is enclosed in the Delaunay circle of triangle abc this is irrelevant. // R is triangle r1, r2, c var r1 = bi + math.normalize(b - bi) * clearance; DebugUtil.DrawLine(r1, r1 + s12); var ac = c - a; var aco = Math.PerpCw(ac); DebugUtil.DrawLine(c, c + aco); var s12o = Math.PerpCw(s12); DebugUtil.DrawLine(c, c + s12o); var r2 = Math.Angle(aco, s12o) < 0 ? Math.IntersectLineLine(r1, r1 + s12, c, c + aco) : Math.IntersectLineLine(r1, r1 + s12, c, c + s12o); DebugUtil.DrawPoint(r1, Color.magenta); DebugUtil.DrawPoint(r2, Color.magenta); if (Math.TriContains(r1, r2, c, v)) { // todo check all edges crossing R to find v, e and u // todo check v is not shared by _two_ collinear constraints var e = c; var u = b; var vi = Math.ProjectLine(s1, s2, v); var lvs = math.length(vi - v); var lve = math.length(e - v); if (lvs < lve) { Assert.IsTrue(lvs <= clearance); // , $"lvs: {lvs} <= clearance: {clearance}"); Math.CircleFromPoints(u, v, e, out var centre, out var radius); var t = Math.IntersectLineCircle(s1, s2, centre, radius, out var x1, out var x2); Assert.IsTrue(t == 2); var pRef = (x1 + x2) / 2; DebugUtil.DrawPoint(pRef, Color.magenta); } } } } DebugUtil.DrawLine(a, b, Color.black); DebugUtil.DrawLine(b, c, Color.black); DebugUtil.DrawLine(c, a, Color.black); }