Esempio n. 1
0
 public static double PixelsToPoints(int pixels, LengthDirection direction)
 {
     if (direction == LengthDirection.Horizontal)
     {
         return(pixels * SystemParameters.WorkArea.Width / Screen.PrimaryScreen.WorkingArea.Width);
     }
     else
     {
         return(pixels * SystemParameters.WorkArea.Height / Screen.PrimaryScreen.WorkingArea.Height);
     }
 }
Esempio n. 2
0
 private double PointsToPixels(double wpfPoints, LengthDirection direction)
 {
     if (direction == LengthDirection.Horizontal)
     {
         return(wpfPoints * Screen.PrimaryScreen.WorkingArea.Width / SystemParameters.WorkArea.Width);
     }
     else
     {
         return(wpfPoints * Screen.PrimaryScreen.WorkingArea.Height / SystemParameters.WorkArea.Height);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Преобразует размер в пикселях экрана в размер в точках WPF.
 /// </summary>
 public static double ConvertPixelsToWpfPoints(int pixels, LengthDirection direction)
 {
     // https://stackoverflow.com/questions/3286175/how-do-i-convert-a-wpf-size-to-physical-pixels
     if (direction == LengthDirection.Horizontal)
     {
         return(pixels * SystemParameters.WorkArea.Width / ScreenWidthInPixels);
     }
     else
     {
         return(pixels * SystemParameters.WorkArea.Height / ScreenHeightInPixels);
     }
 }
        public Polygon2D Geometry2D()
        {
            var normalizedThicknessDirection = ThicknessDirection.ToNormalizedVector();

            if (normalizedThicknessDirection.IsParallelTo(Vector3D.ZAxis))
            {
                var halfLengthVector = ConnectorPlateType.Length / 2 * LengthDirection.ToDirection2D().ToNormalizedVector();
                var halfWidthVector  = ConnectorPlateType.Width / 2 * WidthDirection.ToDirection2D().ToNormalizedVector();
                var center2D         = Center.ToPoint2D();
                return(new Polygon2D
                {
                    Vertices = new List <Point2D>
                    {
                        center2D - halfLengthVector - halfWidthVector,
                        center2D - halfLengthVector + halfWidthVector,
                        center2D + halfLengthVector + halfWidthVector,
                        center2D + halfLengthVector - halfWidthVector,
                    },
                });
            }

            throw new Exception("Connector plate cannot be displayed as a 2D polygon.");
        }
        public Polyhedron Geometry3D()
        {
            var halfLengthVector = ConnectorPlateType.Length / 2 * LengthDirection.ToNormalizedVector();
            var halfWidthVector  = ConnectorPlateType.Width / 2 * WidthDirection.ToNormalizedVector();
            var thicknessVector  = ConnectorPlateType.Thickness * ThicknessDirection.ToNormalizedVector();

            return(new Polyhedron
            {
                Faces = new List <Polygon3D>
                {
                    new Polygon3D
                    {
                        Vertices = new List <Point3D>
                        {
                            Center - halfLengthVector - halfWidthVector,
                            Center - halfLengthVector + halfWidthVector,
                            Center + halfLengthVector + halfWidthVector,
                            Center + halfLengthVector - halfWidthVector,
                        },
                    },
                    new Polygon3D
                    {
                        Vertices = new List <Point3D>
                        {
                            Center - halfLengthVector - halfWidthVector,
                            Center - halfLengthVector + halfWidthVector,
                            Center - halfLengthVector + halfWidthVector + thicknessVector,
                            Center - halfLengthVector - halfWidthVector + thicknessVector,
                        }
                    },
                    new Polygon3D
                    {
                        Vertices = new List <Point3D>
                        {
                            Center - halfLengthVector + halfWidthVector,
                            Center + halfLengthVector + halfWidthVector,
                            Center + halfLengthVector + halfWidthVector + thicknessVector,
                            Center - halfLengthVector + halfWidthVector + thicknessVector,
                        }
                    },
                    new Polygon3D
                    {
                        Vertices = new List <Point3D>
                        {
                            Center + halfLengthVector + halfWidthVector,
                            Center + halfLengthVector - halfWidthVector,
                            Center + halfLengthVector - halfWidthVector + thicknessVector,
                            Center + halfLengthVector + halfWidthVector + thicknessVector,
                        }
                    },
                    new Polygon3D
                    {
                        Vertices = new List <Point3D>
                        {
                            Center + halfLengthVector - halfWidthVector,
                            Center - halfLengthVector - halfWidthVector,
                            Center - halfLengthVector - halfWidthVector + thicknessVector,
                            Center + halfLengthVector - halfWidthVector + thicknessVector,
                        }
                    },
                    new Polygon3D
                    {
                        Vertices = new List <Point3D>
                        {
                            Center + halfLengthVector - halfWidthVector + thicknessVector,
                            Center + halfLengthVector + halfWidthVector + thicknessVector,
                            Center - halfLengthVector + halfWidthVector + thicknessVector,
                            Center - halfLengthVector - halfWidthVector + thicknessVector,
                        }
                    },
                },
            });
        }