Ejemplo n.º 1
0
        private List <FastenerAndNutPartition> CreatePartitions(PolygonalFace faceFromLongestSide, int numberOfPartitions)
        {
            var sortedEdges                 = GeometryFunctions.SortedEdgesOfTriangle(faceFromLongestSide);
            var cornerVer                   = sortedEdges[0].First(sortedEdges[1].Contains);
            var otherVerShertestEdge        = sortedEdges[0].First(a => a != cornerVer);
            var partitionGeneratorDirection = sortedEdges[1].First(a => a != cornerVer).Position.subtract(cornerVer.Position);
            var stepVector                  = partitionGeneratorDirection.divide((double)numberOfPartitions);
            var partis = new List <FastenerAndNutPartition>();

            for (var i = 0; i < NumberOfPartitions; i++)
            {
                var prt = new FastenerAndNutPartition
                {
                    Edge1 =
                        new[]
                    {
                        new Vertex(cornerVer.Position.add(stepVector.multiply(i))),
                        new Vertex(otherVerShertestEdge.Position.add(stepVector.multiply(i)))
                    },
                    Edge2 =
                        new[]
                    {
                        new Vertex(cornerVer.Position.add(stepVector.multiply(i + 1))),
                        new Vertex(otherVerShertestEdge.Position.add(stepVector.multiply(i + 1)))
                    }
                };
                if (i == 0)
                {
                    prt.Edge1 = new[]
                    {
                        new Vertex(cornerVer.Position.add(stepVector.multiply(-0.1))),
                        new Vertex(otherVerShertestEdge.Position.add(stepVector.multiply(-0.1)))
                    };
                }
                if (i == NumberOfPartitions - 1)
                {
                    prt.Edge2 = new[]
                    {
                        new Vertex(cornerVer.Position.add(stepVector.multiply(i + 1.1))),
                        new Vertex(otherVerShertestEdge.Position.add(stepVector.multiply(i + 1.1)))
                    };
                }
                partis.Add(prt);
            }
            return(partis);
        }
 private List<FastenerAndNutPartition> CreatePartitions(Vertex[] startingVerts, double[] partnCreationVect, int numberOfPartitions)
 {
     var stepVector = partnCreationVect.divide((double)numberOfPartitions);
     var partis = new List<FastenerAndNutPartition>();
     for (var i = 0; i < NumberOfPartitions; i++)
     {
         var prt = new FastenerAndNutPartition
         {
             Edge1 =
                 new[]
                 {
                     new Vertex(startingVerts[0].Position.add(stepVector.multiply(i))),
                     new Vertex(startingVerts[1].Position.add(stepVector.multiply(i)))
                 },
             Edge2 =
                 new[]
                 {
                     new Vertex(startingVerts[0].Position.add(stepVector.multiply(i + 1))),
                     new Vertex(startingVerts[1].Position.add(stepVector.multiply(i + 1)))
                 }
         };
         if (i == 0)
         {
             prt.Edge1 = new[]
             {
                 new Vertex(startingVerts[0].Position.add(stepVector.multiply(-0.1))),
                 new Vertex(startingVerts[1].Position.add(stepVector.multiply(-0.1)))
             };
         }
         if (i == NumberOfPartitions - 1)
         {
             prt.Edge2 = new[]
             {
                 new Vertex(startingVerts[0].Position.add(stepVector.multiply(i+1.1))),
                 new Vertex(startingVerts[1].Position.add(stepVector.multiply(i+1.1)))
             };
         }
         partis.Add(prt);
     }
     return partis;
 }
Ejemplo n.º 3
0
        internal static FastenerAndNutPartition PartitionOfThePoint(List <FastenerAndNutPartition> partitions, double[] point)
        {
            FastenerAndNutPartition chosenPrtn = null;
            var sumDisToEdgs = double.PositiveInfinity;

            foreach (var prtn in partitions)
            {
                var dis1 =
                    GeometryFunctions.DistanceBetweenLineAndVertex(
                        prtn.Edge1[0].Position.subtract(prtn.Edge1[1].Position), prtn.Edge1[0].Position,
                        point);
                var dis2 =
                    GeometryFunctions.DistanceBetweenLineAndVertex(
                        prtn.Edge2[0].Position.subtract(prtn.Edge2[1].Position), prtn.Edge2[0].Position,
                        point);
                var sum = dis1 + dis2;
                if (sum < sumDisToEdgs)
                {
                    sumDisToEdgs = sum;
                    chosenPrtn   = prtn;
                }
            }
            return(chosenPrtn);
        }