public void ProjectOn(string p1s, string p2s, string rootPoint, string unitVector, string ep1s, string ep2s) { var p1 = Point3D.Parse(p1s); var p2 = Point3D.Parse(p2s); var line = new Line3D(p1, p2); var plane = new Plane(Point3D.Parse(rootPoint), UnitVector3D.Parse(unitVector)); var expected = new Line3D(Point3D.Parse(ep1s), Point3D.Parse(ep2s)); AssertGeometry.AreEqual(expected, line.ProjectOn(plane)); }
public void MirrorAbout(string ps, string rootPoint, string unitVector, string eps) { var p = Point3D.Parse(ps); var p2 = new Plane(Point3D.Parse(rootPoint), UnitVector3D.Parse(unitVector)); var actual = p.MirrorAbout(p2); var ep = Point3D.Parse(eps); AssertGeometry.AreEqual(ep, actual); }
public void DotProduct(string v1s, string v2s, double expected) { var uv1 = UnitVector3D.Parse(v1s); var uv2 = UnitVector3D.Parse(v2s); var dp = uv1.DotProduct(uv2); Assert.AreEqual(dp, expected, 1e-9); Assert.IsTrue(dp <= 1); Assert.IsTrue(dp >= -1); }
public void SubtractVector(string ps, string vs, string eps) { var p = Point3D.Parse(ps); var actuals = new[] { p - Vector3D.Parse(vs), p - UnitVector3D.Parse(vs) }; var expected = Point3D.Parse(eps); foreach (var actual in actuals) { Assert.AreEqual(expected, actual); } }
public void RotateToTest(string v1s, string v2s, string @as) { UnitVector3D? axis = string.IsNullOrEmpty(@as) ? (UnitVector3D?)null : UnitVector3D.Parse(@as); UnitVector3D v1 = UnitVector3D.Parse(v1s); UnitVector3D v2 = UnitVector3D.Parse(v2s); CoordinateSystem actual = CoordinateSystem.RotateTo(v1, v2, axis); Console.WriteLine(actual); var rv = actual.Transform(v1); AssertGeometry.AreEqual(v2, rv); actual = CoordinateSystem.RotateTo(v2, v1, axis); rv = actual.Transform(v2); AssertGeometry.AreEqual(v1, rv); }
public void InterSectionWithPlaneTest(string pl1s, string pl2s, string eps, string evs) { var plane1 = Plane.Parse(pl1s); var plane2 = Plane.Parse(pl2s); var intersections = new[] { plane1.IntersectionWith(plane2), plane2.IntersectionWith(plane1) }; foreach (var intersection in intersections) { AssertGeometry.AreEqual(Point3D.Parse(eps), intersection.ThroughPoint); AssertGeometry.AreEqual(UnitVector3D.Parse(evs), intersection.Direction); } }
public void InterSectionWithPlane(string rootPoint1, string unitVector1, string rootPoint2, string unitVector2, string eps, string evs) { var plane1 = new Plane(Point3D.Parse(rootPoint1), UnitVector3D.Parse(unitVector1)); var plane2 = new Plane(Point3D.Parse(rootPoint2), UnitVector3D.Parse(unitVector2)); var intersections = new[] { plane1.IntersectionWith(plane2), plane2.IntersectionWith(plane1) }; foreach (var intersection in intersections) { AssertGeometry.AreEqual(Point3D.Parse(eps), intersection.ThroughPoint); AssertGeometry.AreEqual(UnitVector3D.Parse(evs), intersection.Direction); } }
public void Parse(string text, double expectedX, double expectedY, double expectedZ) { Assert.AreEqual(true, UnitVector3D.TryParse(text, out var p)); Assert.AreEqual(expectedX, p.X); Assert.AreEqual(expectedY, p.Y); Assert.AreEqual(expectedZ, p.Z); p = UnitVector3D.Parse(text); Assert.AreEqual(expectedX, p.X); Assert.AreEqual(expectedY, p.Y); Assert.AreEqual(expectedZ, p.Z); p = UnitVector3D.Parse(p.ToString()); Assert.AreEqual(expectedX, p.X); Assert.AreEqual(expectedY, p.Y); Assert.AreEqual(expectedZ, p.Z); }
public void RotationAroundVector(string ps, string @as, string vs, string eps) { var p = Point3D.Parse(ps); var angle = Angle.Parse(@as); var coordinateSystems = new[] { CoordinateSystem.Rotation(angle, UnitVector3D.Parse(vs)), CoordinateSystem.Rotation(angle, Vector3D.Parse(vs)), }; var expected = Point3D.Parse(eps); foreach (var coordinateSystem in coordinateSystems) { var rotatedPoint = coordinateSystem.Transform(p); AssertGeometry.AreEqual(expected, rotatedPoint); } }
public void FromPlanes(string rootPoint1, string unitVector1, string rootPoint2, string unitVector2, string rootPoint3, string unitVector3, string eps) { var plane1 = new Plane(Point3D.Parse(rootPoint1), UnitVector3D.Parse(unitVector1)); var plane2 = new Plane(Point3D.Parse(rootPoint2), UnitVector3D.Parse(unitVector2)); var plane3 = new Plane(Point3D.Parse(rootPoint3), UnitVector3D.Parse(unitVector3)); var p1 = Point3D.IntersectionOf(plane1, plane2, plane3); var p2 = Point3D.IntersectionOf(plane2, plane1, plane3); var p3 = Point3D.IntersectionOf(plane2, plane3, plane1); var p4 = Point3D.IntersectionOf(plane3, plane1, plane2); var p5 = Point3D.IntersectionOf(plane3, plane2, plane1); var ep = Point3D.Parse(eps); foreach (var p in new[] { p1, p2, p3, p4, p5 }) { AssertGeometry.AreEqual(ep, p); } }
public void ParseSwedishUnitVector(string text, double expectedX, double expectedY, double expectedZ) { var culture = CultureInfo.GetCultureInfo("sv"); Assert.AreEqual(true, UnitVector3D.TryParse(text, culture, out var p)); Assert.AreEqual(expectedX, p.X); Assert.AreEqual(expectedY, p.Y); Assert.AreEqual(expectedZ, p.Z); p = UnitVector3D.Parse(text, culture); Assert.AreEqual(expectedX, p.X); Assert.AreEqual(expectedY, p.Y); Assert.AreEqual(expectedZ, p.Z); p = UnitVector3D.Parse(p.ToString(culture)); Assert.AreEqual(expectedX, p.X); Assert.AreEqual(expectedY, p.Y); Assert.AreEqual(expectedZ, p.Z); }
public void PointFromPlanes(string rootPoint1, string unitVector1, string rootPoint2, string unitVector2, string rootPoint3, string unitVector3, string eps) { var plane1 = new Plane(Point3D.Parse(rootPoint1), UnitVector3D.Parse(unitVector1)); var plane2 = new Plane(Point3D.Parse(rootPoint2), UnitVector3D.Parse(unitVector2)); var plane3 = new Plane(Point3D.Parse(rootPoint3), UnitVector3D.Parse(unitVector3)); var points = new[] { Plane.PointFromPlanes(plane1, plane2, plane3), Plane.PointFromPlanes(plane2, plane1, plane3), Plane.PointFromPlanes(plane1, plane3, plane2), Plane.PointFromPlanes(plane2, plane3, plane1), Plane.PointFromPlanes(plane3, plane2, plane1), Plane.PointFromPlanes(plane3, plane1, plane2), }; var expected = Point3D.Parse(eps); foreach (var point in points) { AssertGeometry.AreEqual(expected, point); } }
public void Equals(string p1s, string p2s, double tol, bool expected) { var v1 = UnitVector3D.Parse(p1s); var v2 = UnitVector3D.Parse(p2s); var vector3D = v1.ToVector3D(); Assert.AreEqual(expected, v1 == v2); Assert.IsTrue(v1 == vector3D); Assert.IsTrue(vector3D == v1); Assert.AreEqual(expected, v1.Equals(v2)); Assert.IsTrue(v1.Equals(vector3D)); Assert.IsTrue(vector3D.Equals(v1)); Assert.AreEqual(expected, v1.Equals(v2.ToVector3D())); Assert.AreEqual(expected, v2.ToVector3D().Equals(v1)); Assert.AreEqual(expected, v1.Equals((object)v2)); Assert.AreEqual(expected, Equals(v1, v2)); Assert.AreEqual(expected, v1.Equals(v2, tol)); Assert.AreNotEqual(expected, v1 != v2); Assert.AreNotEqual(expected, v1 != v2.ToVector3D()); Assert.AreNotEqual(expected, v2.ToVector3D() != v1); }
public void SetToRotateToTest(string vs, string vts, string axisString) { var v = UnitVector3D.Parse(vs); var vt = UnitVector3D.Parse(vts); UnitVector3D?axis = null; if (axisString != null) { axis = UnitVector3D.Parse(axisString); } CoordinateSystem cs = CoordinateSystem.RotateTo(v, vt, axis); var rv = cs.Transform(v); AssertGeometry.AreEqual(vt, rv); CoordinateSystem invert = cs.Invert(); Vector3D rotateBack = invert.Transform(rv); AssertGeometry.AreEqual(v, rotateBack); cs = CoordinateSystem.RotateTo(vt, v, axis); rotateBack = cs.Transform(rv); AssertGeometry.AreEqual(v, rotateBack); }
public void MultiplyTest(string unitVectorAsString, double multiplier, string expected) { UnitVector3D unitVector3D = UnitVector3D.Parse(unitVectorAsString); Assert.AreEqual(Vector3D.Parse(expected), multiplier * unitVector3D); }
public void XmlRoundTrips(string rootPoint, string unitVector, string xml) { var plane = new Plane(Point3D.Parse(rootPoint), UnitVector3D.Parse(unitVector)); AssertXml.XmlRoundTrips(plane, xml, (e, a) => AssertGeometry.AreEqual(e, a)); }
public void XmlTests(string ps, string vs, bool asElements, string xml) { var ray = new Ray3D(Point3D.Parse(ps), UnitVector3D.Parse(vs)); AssertXml.XmlRoundTrips(ray, xml, (e, a) => AssertGeometry.AreEqual(e, a, 1e-6)); }
public void ParseFails(string text) { Assert.AreEqual(false, UnitVector3D.TryParse(text, out _)); Assert.Throws <FormatException>(() => UnitVector3D.Parse(text)); }
public UnitVector3D Parse() { return(UnitVector3D.Parse("1; 0; 0", CultureInfo.InvariantCulture, 2)); }