예제 #1
0
        /// <summary>
        /// 値をすべて特定の型に変換する
        /// </summary>
        /// <typeparam name="T">型</typeparam>
        public override void ConvertAll <T>()
        {
            var tempSize   = GetArgSize <T>();
            var tempNumber = Values.Count / tempSize;

            Values = Values.GetRange(0, tempNumber * tempSize);
            Offsets.Clear();
            Numbers.Clear();
            Sizes.Clear();
            Offsets.Add(0);
            Numbers.Add(tempNumber);
            Sizes.Add(Values.Count);
        }
예제 #2
0
        public Dictionary <Tuple <int, int>, double> CalculateRodOffsets()
        {
            Offsets.Clear();

            for (int vStart = 0; vStart < Vertices.Count; vStart++)
            {
                var connectedVertices = Edges.Where(e => e.Item1 == vStart).Select(e => e.Item2).ToList();
                connectedVertices.AddRange(Edges.Where(e => e.Item2 == vStart).Select(e => e.Item1).ToList());

                if (connectedVertices.Count == 1)
                {
                    var key = Tuple.Create(vStart, connectedVertices[0]);

                    if (Offsets.ContainsKey(key))
                    {
                        Offsets[key] = Math.Max(Radius / 2, Offsets[key]);
                    }
                    else
                    {
                        Offsets[key] = Radius / 2;
                    }
                }
                else
                {
                    for (int vEnd = 0; vEnd < connectedVertices.Count; vEnd++)
                    {
                        for (int vCompare = vEnd + 1; vCompare < connectedVertices.Count; vCompare++)
                        {
                            var key1 = Tuple.Create(vStart, connectedVertices[vEnd]);
                            var key2 = Tuple.Create(vStart, connectedVertices[vCompare]);

                            var vec1 = Vertices[connectedVertices[vEnd]] - Vertices[vStart];
                            var vec2 = Vertices[connectedVertices[vCompare]] - Vertices[vStart];

                            var cosAng = (vec1.X * vec2.X + vec1.Y * vec2.Y + vec1.Z * vec2.Z) / (vec1.Length * vec2.Length);
                            var sinAng = Math.Sqrt(Math.Pow(vec1.Length * vec2.Length, 2) -
                                                   Math.Pow(vec1.X * vec2.X + vec1.Y * vec2.Y + vec1.Z * vec2.Z, 2)) / (vec1.Length * vec2.Length);

                            double offset = 0;
                            if (Double.IsNaN(sinAng) || sinAng == 0)
                            {
                                offset = JointThickness + Tolerance;
                            }
                            else if (cosAng <= 0)
                            {
                                offset = Math.Max(JointThickness + Tolerance, OuterWallRadius * sinAng);
                            }
                            else
                            {
                                var off = 1 / sinAng * Math.Sqrt(OuterWallRadius * OuterWallRadius + InnerWallRadius * InnerWallRadius +
                                                                 2 * OuterWallRadius * InnerWallRadius * cosAng - InnerWallRadius * InnerWallRadius * sinAng * sinAng);

                                offset = Math.Max(JointThickness + Tolerance, off);
                            }

                            if (Offsets.ContainsKey(key1))
                            {
                                Offsets[key1] = Math.Max(offset, Offsets[key1]);
                            }
                            else
                            {
                                Offsets[key1] = offset;
                            }

                            if (Offsets.ContainsKey(key2))
                            {
                                Offsets[key2] = Math.Max(offset, Offsets[key2]);
                            }
                            else
                            {
                                Offsets[key2] = offset;
                            }
                        }
                    }
                }
            }

            return(Offsets);
        }