Beispiel #1
0
        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);
        }
Beispiel #2
0
        public override Solid Copy()
        {
            var solid = new CrossSectionSolid(Direction, StepDistances, SameTolerance, Bounds, Units);

            //Recreate the loops, so that the lists are not linked to the original.
            //Since polygonlight is a struct, it will not be linked.
            foreach (var layer in Layer2D)
            {
                solid.Layer2D.Add(layer.Key, new List <PolygonLight>(layer.Value));
            }
            //To create an unlinked copy for layer3D, we need to create new lists and copy the vertices
            foreach (var layer in Layer3D)
            {
                var newLoops = new List <List <Vertex> >();
                foreach (var loop in layer.Value)
                {
                    var newLoop = new List <Vertex>();
                    foreach (var vertex in loop)
                    {
                        newLoop.Add(vertex.Copy());
                    }
                    newLoops.Add(newLoop);
                }
                solid.Layer3D.Add(layer.Key, newLoops);
            }
            if (!Volume.IsNegligible())
            {
                solid.Volume = Volume;
            }
            return(solid);
        }
        public override Solid Copy()
        {
            var solid = new CrossSectionSolid(Direction, StepDistances, SameTolerance, Bounds, Units);

            //Recreate the loops, so that the lists are not linked to the original.
            foreach (var layer in Layer2D)
            {
                solid.Layer2D.Add(layer.Key, new List <Polygon>(layer.Value));
            }
            solid._volume        = _volume;
            solid._center        = _center;
            solid._inertiaTensor = _inertiaTensor;
            solid._surfaceArea   = _surfaceArea;
            return(solid);
        }