/// <summary> /// Gets outline corners of a box as seen from given position (in clockwise order). /// Returns null if position is inside the box. /// </summary> public static V3d[] GetOutlineCornersCW(this Box3d box, V3d fromPosition) { var cs = box.ComputeCorners(); return(GetOutlineCornerIndicesCW(box, fromPosition).Map(i => cs[i])); }
/// <summary> /// Gets outline corner indices of a box as seen from given position (in clockwise order). /// Returns null if position is inside the box. /// </summary> public static int[] GetOutlineCornerIndicesCW(this Box3d box, V3d fromPosition) { var cs = box.ComputeCorners(); if (fromPosition.X < box.Min.X) { //-X if (fromPosition.Y < box.Min.Y) { //-Y if (fromPosition.Z < box.Min.Z) { // -X -Y -Z return(new[] { 1, 3, 2, 6, 4, 5 }); } else if (fromPosition.Z > box.Max.Z) { // -X -Y +Z return(new[] { 0, 2, 6, 7, 5, 1 }); } else { // -X -Y Z return(new[] { 1, 2, 6, 5 }); } } else if (fromPosition.Y > box.Max.Y) { // +Y if (fromPosition.Z < box.Min.Z) { // -X +Y -Z return(new[] { 0, 1, 3, 7, 6, 4 }); } else if (fromPosition.Z > box.Max.Z) { // -X +Y +Z return(new[] { 0, 2, 3, 7, 5, 4 }); } else { // -X +Y Z return(new[] { 0, 3, 7, 4 }); } } else { // Y if (fromPosition.Z < box.Min.Z) { // -X Y -Z return(new[] { 1, 3, 6, 4 }); } else if (fromPosition.Z > box.Max.Z) { // -X Y +Z return(new[] { 0, 2, 7, 5 }); } else { // -X Y Z return(new[] { 0, 2, 6, 4 }); } } } else if (fromPosition.X > box.Max.X) { // +X if (fromPosition.Y < box.Min.Y) { //-Y if (fromPosition.Z < box.Min.Z) { // +X -Y -Z return(new[] { 0, 4, 5, 7, 3, 2 }); } else if (fromPosition.Z > box.Max.Z) { // +X -Y +Z return(new[] { 0, 4, 6, 7, 3, 1 }); } else { // +X -Y Z return(new[] { 0, 4, 7, 3 }); } } else if (fromPosition.Y > box.Max.Y) { // +Y if (fromPosition.Z < box.Min.Z) { // +X +Y -Z return(new[] { 0, 1, 5, 7, 6, 2 }); } else if (fromPosition.Z > box.Max.Z) { // +X +Y +Z return(new[] { 1, 5, 4, 6, 2, 3 }); } else { // +X +Y Z return(new[] { 1, 5, 6, 2 }); } } else { // Y if (fromPosition.Z < box.Min.Z) { // +X Y -Z return(new[] { 0, 5, 7, 2 }); } else if (fromPosition.Z > box.Max.Z) { // +X Y +Z return(new[] { 1, 4, 6, 3 }); } else { // +X Y Z return(new[] { 1, 5, 7, 3 }); } } } else { // X if (fromPosition.Y < box.Min.Y) { //-Y if (fromPosition.Z < box.Min.Z) { // X -Y -Z return(new[] { 2, 4, 5, 3 }); } else if (fromPosition.Z > box.Max.Z) { // X -Y +Z return(new[] { 0, 6, 7, 1 }); } else { // X -Y Z return(new[] { 0, 4, 5, 1 }); } } else if (fromPosition.Y > box.Max.Y) { // +Y if (fromPosition.Z < box.Min.Z) { // X +Y -Z return(new[] { 0, 1, 7, 6 }); } else if (fromPosition.Z > box.Max.Z) { // X +Y +Z return(new[] { 2, 3, 5, 4 }); } else { // X +Y Z return(new[] { 2, 3, 7, 6 }); } } else { // Y if (fromPosition.Z < box.Min.Z) { // X Y -Z return(new[] { 0, 1, 3, 2 }); } else if (fromPosition.Z > box.Max.Z) { // X Y +Z return(new[] { 4, 6, 7, 5 }); } else { // X Y Z return(null); } } } }