//Good Game private void CalcNearestPoint(out VInt3 cp, ref VInt3 start, ref VInt3 end, ref VInt3 p) { VInt2 b = new VInt2(end.x - start.x, end.z - start.z); long sqrMagnitudeLong = b.sqrMagnitudeLong; VInt2 a = new VInt2(p.x - start.x, p.z - start.z); cp = new VInt3(); cp.y = p.y; long num4 = VInt2.DotLong(ref a, ref b); if (sqrMagnitudeLong != 0) { long num5 = (end.x - start.x) * num4; long num6 = (end.z - start.z) * num4; cp.x = (int)IntMath.Divide(num5, sqrMagnitudeLong); cp.z = (int)IntMath.Divide(num6, sqrMagnitudeLong); cp.x += start.x; cp.z += start.z; } else { int num7 = (int)num4; cp.x = start.x + ((end.x - start.x) * num7); cp.z = start.z + ((end.z - start.z) * num7); } }
private void CalcNearestPoint(out VInt3 cp, ref VInt3 start, ref VInt3 end, ref VInt3 p) { VInt2 vInt = new VInt2(end.x - start.x, end.z - start.z); long sqrMagnitudeLong = vInt.sqrMagnitudeLong; VInt2 vInt2 = new VInt2(p.x - start.x, p.z - start.z); cp = default(VInt3); cp.y = p.y; long num = VInt2.DotLong(ref vInt2, ref vInt); if (sqrMagnitudeLong != 0L) { long a = (long)(end.x - start.x) * num; long a2 = (long)(end.z - start.z) * num; cp.x = (int)IntMath.Divide(a, sqrMagnitudeLong); cp.z = (int)IntMath.Divide(a2, sqrMagnitudeLong); cp.x += start.x; cp.z += start.z; } else { int num2 = (int)num; cp.x = start.x + (end.x - start.x) * num2; cp.z = start.z + (end.z - start.z) * num2; } }
public static float NearestPointFactor(VInt2 lineStart, VInt2 lineEnd, VInt2 point) { VInt2 b = lineEnd - lineStart; double sqrMagnitudeLong = b.sqrMagnitudeLong; double num3 = VInt2.DotLong(point - lineStart, b); if (sqrMagnitudeLong != 0.0) { num3 /= sqrMagnitudeLong; } return((float)num3); }
public static float NearestPointFactor(VInt2 lineStart, VInt2 lineEnd, VInt2 point) { VInt2 b = lineEnd - lineStart; double num = (double)b.sqrMagnitudeLong; double num2 = (double)VInt2.DotLong(point - lineStart, b); if (num != 0.0) { num2 /= num; } return((float)num2); }
public static VFactor NearestPointFactorXZ(ref VInt3 lineStart, ref VInt3 lineEnd, ref VInt3 point) { VInt2 b = new VInt2(lineEnd.x - lineStart.x, lineEnd.z - lineStart.z); VInt2 a = new VInt2(point.x - lineStart.x, point.z - lineStart.z); long sqrMagnitudeLong = b.sqrMagnitudeLong; VFactor zero = VFactor.zero; zero.nom = VInt2.DotLong(a, b); if (sqrMagnitudeLong != 0) { zero.den = sqrMagnitudeLong; } return(zero); }
/** Factor of the nearest point on the segment. * Returned value is in the range [0,1] if the point lies on the segment otherwise it just lies on the line. * The closest point can be calculated using (end-start)*factor + start; */ public static long ClosestPointOnLineFactor(VInt2 lineStart, VInt2 lineEnd, VInt2 point) { var lineDirection = lineEnd - lineStart; long magn = lineDirection.sqrMagnitudeLong; long closestPoint = VInt2.DotLong(point - lineStart, lineDirection); if (magn != 0) { closestPoint /= magn; } return(closestPoint); }
public static VInt2 ClosestPointOnSegment(VInt2 lineStart, VInt2 lineEnd, VInt2 point) { var dir = lineEnd - lineStart; long sqrMagn = dir.sqrMagnitudeLong; if (sqrMagn <= 1) { return(lineStart); } long factor = VInt2.DotLong(point - lineStart, dir) / sqrMagn; return(lineStart + dir * (int)IntMath.Clamp(0, 1000, factor)); }