public static Vector3 UnitVector(CartesianDirections direction) { switch (direction) { case CartesianDirections.XNegative: return(new Vector3(-1, 0, 0)); case CartesianDirections.XPositive: return(new Vector3(1, 0, 0)); case CartesianDirections.YNegative: return(new Vector3(0, -1, 0)); case CartesianDirections.YPositive: return(new Vector3(0, 1, 0)); case CartesianDirections.ZNegative: return(new Vector3(0, 0, -1)); default: return(new Vector3(0, 0, 1)); } }
/// <summary> /// Moves the face outward by the provided distance (or inward if distance is negative) /// </summary> /// <param name="face">The face as defined by the CartesianDirections enumerator. This is the local x,y,z - not the global.</param> /// <param name="distance">The distance to move the face by (negative will move the face inward).</param> public override void MoveFaceOutward(CartesianDirections face, double distance) { base.MoveFaceOutward(face, distance); if (distance.IsNegligible()) { return; } var negativeFace = face < 0; var direction = Math.Abs((int)face) - 1; if (PointsOnFaces != null) { //direction1-low, /// direction1-high, direction2-low, direction2-high, direction3-low, direction3-high. var vertexOnPlaneIndex = 2 * direction + (!negativeFace ? 1 : 0); PointsOnFaces[vertexOnPlaneIndex] = Array.Empty <T>(); } }
public static List <PolygonLight>[] GetUniformlySpacedSlices(TessellatedSolid ts, CartesianDirections direction, double startDistanceAlongDirection = double.NaN, int numSlices = -1, double stepSize = double.NaN) { if (double.IsNaN(stepSize) && numSlices < 1) { throw new ArgumentException("Either a valid stepSize or a number of slices greater than zero must be specified."); } var intDir = Math.Abs((int)direction) - 1; var lengthAlongDir = ts.Bounds[1][intDir] - ts.Bounds[0][intDir]; stepSize = Math.Abs(stepSize); if (double.IsNaN(stepSize)) { stepSize = lengthAlongDir / numSlices; } if (numSlices < 1) { numSlices = (int)(lengthAlongDir / stepSize); } if (double.IsNaN(startDistanceAlongDirection)) { if (direction < 0) { startDistanceAlongDirection = ts.Bounds[1][intDir] - 0.5 * stepSize; } else { startDistanceAlongDirection = ts.Bounds[0][intDir] + 0.5 * stepSize; } } switch (direction) { case CartesianDirections.XPositive: return(AllSlicesAlongX(ts, startDistanceAlongDirection, numSlices, stepSize)); case CartesianDirections.YPositive: return(AllSlicesAlongY(ts, startDistanceAlongDirection, numSlices, stepSize)); case CartesianDirections.ZPositive: return(AllSlicesAlongZ(ts, startDistanceAlongDirection, numSlices, stepSize)); case CartesianDirections.XNegative: return(AllSlicesAlongX(ts, startDistanceAlongDirection, numSlices, stepSize).Reverse().ToArray()); case CartesianDirections.YNegative: return(AllSlicesAlongY(ts, startDistanceAlongDirection, numSlices, stepSize).Reverse().ToArray()); default: return(AllSlicesAlongZ(ts, startDistanceAlongDirection, numSlices, stepSize).Reverse().ToArray()); } }
public static CrossSectionSolid CreateFromTessellatedSolid(TessellatedSolid ts, CartesianDirections direction, int numberOfLayers) { var intDir = Math.Abs((int)direction) - 1; var lengthAlongDir = ts.Bounds[1][intDir] - ts.Bounds[0][intDir]; var stepSize = lengthAlongDir / numberOfLayers; var stepDistances = new Dictionary <int, double>(); //var stepDistances = new double[numberOfLayers]; stepDistances.Add(0, ts.Bounds[0][intDir] + 0.5 * stepSize); //stepDistances[0] = ts.Bounds[0][intDir] + 0.5 * stepSize; for (int i = 1; i < numberOfLayers; i++) { stepDistances.Add(i, stepDistances[i - 1] + stepSize); } //stepDistances[i] = stepDistances[i - 1] + stepSize; var bounds = new[] { (double[])ts.Bounds[0].Clone(), (double[])ts.Bounds[1].Clone() }; var layers = CrossSectionSolid.GetUniformlySpacedSlices(ts, direction, stepDistances[0], numberOfLayers, stepSize); var layerDict = new Dictionary <int, List <PolygonLight> >(); for (int i = 0; i < layers.Length; i++) { layerDict.Add(i, layers[i]); } var directionVector = new double[3]; directionVector[intDir] = Math.Sign((int)direction); var cs = new CrossSectionSolid(directionVector, stepDistances, ts.SameTolerance, layerDict, bounds, ts.Units); //var cs = new CrossSectionSolid(stepDistances, layers, bounds, ts.Units); cs.TranformMatrix = StarMath.makeIdentity(4); return(cs); }
public static CrossSectionSolid CreateFromTessellatedSolid(TessellatedSolid ts, CartesianDirections direction, int numberOfLayers) { var intDir = Math.Abs((int)direction) - 1; var max = intDir == 0 ? ts.Bounds[1].X : intDir == 1 ? ts.Bounds[1].Y : ts.Bounds[1].Z; var min = intDir == 0 ? ts.Bounds[0].X : intDir == 1 ? ts.Bounds[0].Y : ts.Bounds[0].Z; var lengthAlongDir = max - min; var stepSize = lengthAlongDir / numberOfLayers; var stepDistances = new Dictionary <int, double>(); //var stepDistances = new double[numberOfLayers]; stepDistances.Add(0, min + 0.5 * stepSize); //stepDistances[0] = ts.Bounds[0][intDir] + 0.5 * stepSize; for (int i = 1; i < numberOfLayers; i++) { stepDistances.Add(i, stepDistances[i - 1] + stepSize); } //stepDistances[i] = stepDistances[i - 1] + stepSize; var bounds = new[] { ts.Bounds[0].Copy(), ts.Bounds[1].Copy() }; var layers = ts.GetUniformlySpacedCrossSections(direction, stepDistances[0], numberOfLayers, stepSize); var layerDict = new Dictionary <int, IList <Polygon> >(); for (int i = 0; i < layers.Length; i++) { layerDict.Add(i, layers[i]); } var directionVector = Vector3.UnitVector(direction); return(new CrossSectionSolid(directionVector, stepDistances, ts.SameTolerance, layerDict, bounds, ts.Units)); }