コード例 #1
0
ファイル: Planimetrics.cs プロジェクト: majasinski/BridgeOpt
        public CentralTriangle(Vector <double> a, Vector <double> b)
        {
            Vectors.Add(a);
            Vectors.Add(b);

            double normalLength = a.First() * b.Last() - a.Last() * b.First(); //Length of a vector product

            if (Math.Abs(normalLength) < double.Epsilon)
            {
                Sign = Sign.Zero;
            }
            else if (normalLength > 0)
            {
                Sign = Sign.Positive;
            }
            else
            {
                Sign = Sign.Negative;
            }

            if (Sign != Sign.Zero)
            {
                Area = 0.5 * Math.Abs(normalLength);
                Vector <double> gravityCenterVector = a.Add(b) / 3;

                GravityCenter.X = gravityCenterVector[0];
                GravityCenter.Y = gravityCenterVector[1];

                StaticMoments    = new StaticMoments(GetStaticMoment(Axle.X), GetStaticMoment(Axle.Y));
                MomentsOfInertia = new MomentsOfInertia(GetMomentOfInertia(Axle.X), GetMomentOfInertia(Axle.Y));
            }
            else
            {
                Area            = 0.0;
                GravityCenter.X = 0.0;
                GravityCenter.Y = 0.0;

                StaticMoments    = new StaticMoments(0.0, 0.0);
                MomentsOfInertia = new MomentsOfInertia(0.0, 0.0);
            }
        }
コード例 #2
0
ファイル: Planimetrics.cs プロジェクト: majasinski/BridgeOpt
            public CrossSection(List <Point> points)
            {
                Vertices = points;

                Boundaries       = new Boundaries();
                StaticMoments    = new StaticMoments();
                MomentsOfInertia = new MomentsOfInertia();

                Boundaries.Left   = points[0].X;
                Boundaries.Right  = points[0].X;
                Boundaries.Bottom = points[0].Y;
                Boundaries.Top    = points[0].Y;

                if (points.First() != points.Last())
                {
                    points.Add(points[0]);
                }

                for (int i = 0; i < points.Count() - 1; i++)
                {
                    Triangles.Add(new CentralTriangle(points[i], points[i + 1]));

                    Area             += ((int)Triangles.Last().Sign) * Triangles.Last().Area;
                    StaticMoments.SX += ((int)Triangles.Last().Sign) * Triangles.Last().StaticMoments.SX;
                    StaticMoments.SY += ((int)Triangles.Last().Sign) * Triangles.Last().StaticMoments.SY;

                    if (points[i].X < Boundaries.Left)
                    {
                        Boundaries.Left = points[i].X;
                    }
                    if (points[i].X > Boundaries.Right)
                    {
                        Boundaries.Right = points[i].X;
                    }
                    if (points[i].Y < Boundaries.Bottom)
                    {
                        Boundaries.Bottom = points[i].Y;
                    }
                    if (points[i].Y > Boundaries.Top)
                    {
                        Boundaries.Top = points[i].Y;
                    }
                }
                if (Area < 0.0)
                {
                    throw new Exception("Invalid shape definition.");
                }

                GravityCenter = new Point(StaticMoments.SY / Area, StaticMoments.SX / Area);

                Boundaries.Left   = Boundaries.Left - GravityCenter.X;
                Boundaries.Right  = Boundaries.Right - GravityCenter.X;
                Boundaries.Bottom = Boundaries.Bottom - GravityCenter.Y;
                Boundaries.Top    = Boundaries.Top - GravityCenter.Y;

                foreach (CentralTriangle triangle in Triangles)
                {
                    MomentsOfInertia.IX += ((int)triangle.Sign) * (triangle.MomentsOfInertia.IX + triangle.Area * Math.Pow(GravityCenter.Y - triangle.GravityCenter.Y, 2) - triangle.Area * Math.Pow(triangle.GravityCenter.Y, 2));
                    MomentsOfInertia.IY += ((int)triangle.Sign) * (triangle.MomentsOfInertia.IY + triangle.Area * Math.Pow(GravityCenter.X - triangle.GravityCenter.X, 2) - triangle.Area * Math.Pow(triangle.GravityCenter.X, 2));
                }
            }