public void AbsoluteLocationLinear() { var root = new Body { Location = new Frame3D(0, 0, 10) }; Assert.AreEqual(root.Location, root.GetAbsoluteLocation()); var box = new Box { Location = new Frame3D(10, 0, 0) }; Assert.AreEqual(box.Location, box.GetAbsoluteLocation()); root.Add(box); Assert.AreEqual(box.Location.Apply(root.Location), box.GetAbsoluteLocation()); int sum = 0; for (int i = 0; i < 10; i++) { sum += i; Body child = new Box { Location = new Frame3D(i, 0, 0) }; root.Add(child); Assert.AreEqual(sum, child.GetAbsoluteLocation().X); root = child; } }
public void AbsoluteLocationLinear() { var root = new Body {Location = new Frame3D(0, 0, 10)}; Assert.AreEqual(root.Location, root.GetAbsoluteLocation()); var box = new Box {Location = new Frame3D(10, 0, 0)}; Assert.AreEqual(box.Location, box.GetAbsoluteLocation()); root.Add(box); Assert.AreEqual(box.Location.Apply(root.Location), box.GetAbsoluteLocation()); int sum = 0; for(int i = 0; i < 10; i++) { sum += i; Body child = new Box {Location = new Frame3D(i, 0, 0)}; root.Add(child); Assert.AreEqual(sum, child.GetAbsoluteLocation().X); root = child; } }
public static Ball GetExternalSphere(Box box) { var vectors = GetDirection(box); var up = vectors[2]; Point3D center = box.GetAbsoluteLocation().ToPoint3D() + (0.5*up*box.ZSize); double radius = Math.Sqrt(Math.Pow(0.5*box.ZSize, 2.0) + Math.Pow(0.5*box.YSize, 2.0) + Math.Pow(0.5*box.XSize, 2.0)); Point3D locaction = center - up.Normalize()*radius; return new Ball(){Location = locaction.ToFrame(), Radius = radius}; }
public void TreeMovingNoParent() { var oldBoxLocation = new Frame3D(10, 20, 30); var box = new Box { Location = oldBoxLocation }; var newParent = new Body { Location = new Frame3D(20, 10, 20) }; newParent.DetachAttachMaintaingLoction(box); Assert.AreEqual(oldBoxLocation, box.GetAbsoluteLocation()); Assert.AreEqual(new Frame3D(-10, 10, 10), box.Location); }
public static List<Point3D> GetVertex(Box box) { var location = box.GetAbsoluteLocation().ToPoint3D(); var x = box.XSize; var y = box.YSize; var z = box.ZSize; Point3D[] vectors = GetDirection(box); var nUp = vectors[2]; var nLeft = -vectors[1]; var nFront = vectors[0]; var vertex = new List<Point3D> { location + 0.5*nLeft*y - 0.5*nFront*x, location + 0.5*nLeft*y + 0.5*nFront*x, location - 0.5*nLeft*y - 0.5*nFront*x, location + nUp*z + 0.5*nLeft*y - 0.5*nFront*x, location - 0.5*nLeft*y + 0.5*nFront*x, location + nUp*z - 0.5*nLeft*y - 0.5*nFront*x, location + nUp*z + 0.5*nLeft*y + 0.5*nFront*x, location + nUp*z - 0.5*nLeft*y + 0.5*nFront*x }; return vertex; }