public MyLine3D(MyPoint from, MyPoint to, bool ispa)
 {
     fromNode   = from;
     toNode     = to;
     isParallel = ispa;
 }
 public MyLine3D(float x1, float y1, float z1, float x2, float y2, float z2, bool ispa)
 {
     fromNode   = new MyPoint(x1, y1, z1);
     toNode     = new MyPoint(x2, y2, z2);
     isParallel = ispa;
 }
 public PointF projectionPerspective(MyPoint viewPoint)
 {
     return(new PointF(viewPoint.X + (X - viewPoint.X) * viewPoint.Z / (viewPoint.Z - Z), viewPoint.Y + (Y - viewPoint.Y) * viewPoint.Z / (viewPoint.Z - Z)));
 }
 public PointF projectionParallel(MyPoint direction)
 {
     return(new PointF(X - Z * direction.X / direction.Z, Y - Z * direction.Y / direction.Z));
 }
 public PointF projectionPerspective(MyPoint poi)
 {
     return(new PointF(viewPoint.X + (poi.X - viewPoint.X) * viewPoint.Z / (viewPoint.Z - poi.Z), viewPoint.Y + (poi.Y - viewPoint.Y) * viewPoint.Z / (viewPoint.Z - poi.Z)));
 }
 public PointF projectionParallel(MyPoint poi)
 {
     return(new PointF(poi.X - poi.Z * viewPoint.X / viewPoint.Z, poi.Y - poi.Z * viewPoint.Y / viewPoint.Z));
 }
Пример #7
0
        private void pictureBoxDown_Paint(object sender, PaintEventArgs e)
        {
            /* ********************************
             * 绘制坐标系
             * 主要绘制的是坐标轴
             * ***********************/
            Graphics g = e.Graphics;
            Pen      pen = new Pen(Color.Black);
            int      width = pictureBoxDown.Width, height = pictureBoxDown.Height;
            Point    pO = new Point(width / 2 - 10, height / 2 + 2);
            Point    pX = new Point(width - 10, height / 2 + 2);
            Point    pY = new Point(width / 2 + 1, 0);
            Font     f  = new Font("Arial", 8);

            g.DrawString("O", f, Brushes.Black, pO);
            g.DrawString("X", f, Brushes.Black, pX);
            g.DrawString("Y", f, Brushes.Black, pY);
            g.DrawLine(pen, width / 2, 0, width / 2, height / 2);
            g.DrawLine(pen, width / 2, 0, width / 2 - 2, 5);
            g.DrawLine(pen, width / 2, 0, width / 2 + 2, 5);
            g.DrawLine(pen, width / 2, height / 2, width, height / 2);
            g.DrawLine(pen, width - 5, height / 2 - 2, width, height / 2);
            g.DrawLine(pen, width - 5, height / 2 + 2, width, height / 2);

            //接下来是画 z 轴
            //投影 z 轴上足够远得一点
            PointF pZ;

            if (isParallel)
            {
                //pZ = new MyPoint(0, 0, 50000).projectionParallel(station);
                pZ = new MyPoint(0, 0, station.Z / 2).projectionParallel(station);
                pZ = getEnd(new PointF(0, 0), pZ, 5000);
            }
            else
            {
                pZ = new MyPoint(0, 0, station.Z / 2).projectionPerspective(station);
                pZ = getEnd(new PointF(0, 0), pZ, 5000);
            }

            if (pZ.X >= width / 2 - 20)
            {
                pZ = new PointF(width / 2 - 20, pZ.Y * (width / 2 - 20) / pZ.X);
            }
            else if (pZ.X <= -width / 2 + 10)
            {
                pZ = new PointF(-width / 2 + 20, pZ.Y * (-width / 2 + 20) / pZ.X);
            }
            if (pZ.Y >= height / 2 - 20)
            {
                pZ = new PointF(pZ.X * (height / 2 - 20) / pZ.Y, height / 2 - 20);
            }
            else if (pZ.Y <= -height / 2 + 20)
            {
                pZ = new PointF(pZ.X * (-height / 2 + 20) / pZ.Y, -height / 2 + 20);
            }
            //将 pZ 变换到显示坐标系中去
            g.DrawLine(pen, width / 2, height / 2, pZ.X + width / 2, -pZ.Y + height / 2);


            if (pZ.X == 0 && pZ.Y == 0)
            {
                g.FillEllipse(Brushes.Red, width / 2 - 1, height / 2 - 1, 2, 2);
                g.DrawString("Z", f, Brushes.Black, pZ.X + width / 2, pZ.Y + height / 2);
            }
            else
            {
                PointF end = getEnd(pZ, Math.Atan2(pZ.Y, pZ.X) - 0.4 + Math.PI, 8);
                g.DrawLine(pen, pZ.X + width / 2, -pZ.Y + height / 2, end.X + width / 2, -end.Y + height / 2);
                end = getEnd(pZ, Math.Atan2(pZ.Y, pZ.X) + 0.4 + Math.PI, 8);
                g.DrawLine(pen, pZ.X + width / 2, -pZ.Y + height / 2, end.X + width / 2, -end.Y + height / 2);
                end = getEnd(pZ, Math.Atan2(pZ.Y, pZ.X), 8);
                g.DrawString("Z", f, Brushes.Black, end.X + width / 2, -end.Y + height / 2);
            }
        }