public static ESplitType ClassifyPointToPlane(SplitPlane plane, LVector2 vertex) { var val = LVector2.Cross(plane.dir, vertex - plane.a); if (val == 0) { return(ESplitType.OnPlane); } else { return(val < 0 ? ESplitType.Right : ESplitType.Left); } }
private void TestLVector2() { LVector2 v1 = new LVector2(3.3d, 1.2d); LVector2 v2 = new LVector2(1.2d, 3.3d); AssertTrue(v1 != v2); AssertFalse(v1 == v2); AssertTrue(v1 + v2 == new LVector2(4.5d, 4.5d)); AssertTrue(v1 - v2 == new LVector2(2.1d, -2.1d)); AssertTrue(v1 * 2 == new LVector2(6.6d, 2.4d)); AssertTrue(v1 / 3 == new LVector2(1.1d, 0.4d)); AssertTrue(LVector2.zero.normalized == LVector2.zero); AssertTrue(LVector2.Dot(v1, v2) == 7.92d); Debug.Log(v1.sqrMagnitude); Debug.Log(v1.magnitude); Debug.Log(v1.normalized); Debug.Log(LVector2.Cross(v1, v2)); Debug.Log("----------------------"); }
public static ESplitType GetSplitResult(SplitPlane plane, TriRef tri) { var planeDir = plane.dir; var valA = LVector2.Cross(planeDir, tri.a - plane.a); var valB = LVector2.Cross(planeDir, tri.b - plane.a); var valC = LVector2.Cross(planeDir, tri.c - plane.a); var isRight = false; if (valA != 0) { isRight = valA < 0; } if (valB != 0) { isRight = valB < 0; } if (valC != 0) { isRight = valC < 0; } var isA = valA <= 0; var isB = valB <= 0; var isC = valC <= 0; if (isA == isB && isB == isC) { return(isRight ? ESplitType.Right : ESplitType.Left); } isA = valA >= 0; isB = valB >= 0; isC = valC >= 0; if (isA == isB && isB == isC) { return(isRight ? ESplitType.Right : ESplitType.Left); } return(ESplitType.OnPlane); }
public bool Contain(LVector2 pos) { var isRightA = LVector2.Cross(b - a, pos - a) > 0; if (isRightA) { return(false); } var isRightB = LVector2.Cross(c - b, pos - b) > 0; if (isRightB) { return(false); } var isRightC = LVector2.Cross(a - c, pos - c) > 0; if (isRightC) { return(false); } return(true); }
public LFloat Cross(LVector2 v) { return(LVector2.Cross(this, v)); }