Exemple #1
0
        /// <summary>
        /// 判断点是否嵌入了表面所在的板件
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="peakValue">嵌入板件的深度值,按照设计这个值应当是负值</param>
        /// <param name="associateDist">判定时的容差,为正值</param>
        /// <returns></returns>
        private bool IsDistEnough(PartFace anotherFace, Point3d pt, double peakValue, double associateDist)
        {
            //先把世界坐标系下的pt转换成mp坐标系下
            pt = pt.TransformBy(Matrix3d.AlignCoordinateSystem(anotherFace.Part.MovedMPPoint,
                                                               anotherFace.Part.MovedMPXAxis,
                                                               anotherFace.Part.MovedMPYAxis,
                                                               anotherFace.Part.MovedMPZAxis,
                                                               Point3d.Origin,
                                                               Vector3d.XAxis,
                                                               Vector3d.YAxis,
                                                               Vector3d.ZAxis));

            //取有效数字两个,是为了避免精确计算的情况下的误差导致判断错误
            double z = System.Math.Round(pt.Z, 2);

            //面5和面6的判断不同,这是因为Z的正方向发生了变化
            double zlimitDown = 0 - peakValue;
            double zlimitUp   = associateDist - peakValue;

            if (anotherFace.FaceNumber == 6)
            {
                zlimitUp   = associateDist + this.Part.Thickness + peakValue;
                zlimitDown = this.Part.Thickness + peakValue;
            }
            if (z >= zlimitDown && z <= zlimitUp)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public Plane Plane { get; set; }//面所在的CAD平面,用于一些面的关系的判断,如平行、距离

        /// <summary>
        /// 
        /// </summary>
        /// <param name="anotherFace"></param>
        /// <param name="dist">容忍距离值,包含容差,通常为1</param>
        /// <param name="IsDado">是否为开槽类的关联机加工</param>
        /// <returns></returns>
        public bool IsAssocaitedWithAnotherFace(PartFace anotherFace, double dist)
        {
            /*
             * 判断原则
             * 1、两个面平行且距离小于某个固定值
             * 2A、指令面的所有顶点,投影到被关联面,至少有一个点位于关联面的内部
             * 2B、(改进算法)指令面的两个对角点,如果投影后都在另一个面内部,则认为是关联的,
             *     如果不是都在则有可能一个或两个都不在内部
             *     做一条线段链接起来,和另一面的四条边做交点
             *     如果有一个交点则是关联的
             * 3、如果是开槽关联,则上述两条不适用
             */

            //如果他们是同一个板件的不同面,永远都是不关联的
            if (this.Part == anotherFace.Part)
                return false;

            //如果两个面不平行,那也是不关联的
            //TODO:这里用到了Plane属于CAD的实体,是否会造成内存泄漏?
            if (!anotherFace.Plane.IsParallelTo(this.Plane))
            {
                return false;
            }

            //如果两个面的距离大于一定距离也就不关联
            if (anotherFace.Plane.DistanceTo(this.Point1) > dist)
            {
                return false;
            }

            //如果是开槽这样的关联,就需要注意的:
            //1、两个板件得有交集
            //2、距离值较大
            //3、嵌入值如何界定?

            //计算所在面的四个点,共有几个点落在另一个面的板件范围内
            int PtInPartsCount = this.Points.Count(pt => anotherFace.IsPointIn(pt, dist));
            //对于所关联的面是面5、面6或者是4个边,对点的数量要求也不同
            if (anotherFace.IsHorizontalFace && PtInPartsCount == 4)
            {
                return true;
            }
            else if (!anotherFace.IsHorizontalFace)
            {
                if (PtInPartsCount <= 2)
                {
                    //对于没有一个点在内部的情况,要判断对角线与板件四边的投影线是否有交点
                    return anotherFace.IsLineCrossBorder(this.Point1, this.Point3);
                }
                else
                {
                    //三个以上的,就必然了
                    return true;
                }
            }

            return false;
        }
        private void SetFaces()
        {
            Point3d p1 = Point3d.Origin;
            Point3d p2 = Point3d.Origin;
            Point3d p3 = Point3d.Origin;
            Point3d p4 = Point3d.Origin;
            Point3d p5 = Point3d.Origin;
            Point3d p6 = Point3d.Origin;
            Point3d p7 = Point3d.Origin;
            Point3d p8 = Point3d.Origin;
            if (!this.MachinePoint.IsRotated)
            {
                p1 = new Point3d(0, 0, 0);
                p2 = new Point3d(0, 0, Thickness);
                p3 = new Point3d(0, Width, 0);
                p4 = new Point3d(0, Width, Thickness);
                p5 = new Point3d(Length, Width, 0);
                p6 = new Point3d(Length, Width, Thickness);
                p7 = new Point3d(Length, 0, 0);
                p8 = new Point3d(Length, 0, Thickness);
            }
            else
            {
                p1 = new Point3d(0, 0, 0);
                p2 = new Point3d(0, 0, Thickness);
                p3 = new Point3d(0, Length, 0);
                p4 = new Point3d(0, Length, Thickness);
                p5 = new Point3d(Width, Length, 0);
                p6 = new Point3d(Width, Length, Thickness);
                p7 = new Point3d(Width, 0, 0);
                p8 = new Point3d(Width, 0, Thickness);
            }

            //将p1-p8从MP坐标系转换成为世界坐标系下的坐标
            p1 = p1.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p2 = p2.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p3 = p3.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p4 = p4.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p5 = p5.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p6 = p6.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p7 = p7.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p8 = p8.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p1 = MathHelper.GetRotatedAndMovedPoint(p1, TXRotation, TYRotation, TZRotation, CenterVector);
            p2 = MathHelper.GetRotatedAndMovedPoint(p2, TXRotation, TYRotation, TZRotation, CenterVector);
            p3 = MathHelper.GetRotatedAndMovedPoint(p3, TXRotation, TYRotation, TZRotation, CenterVector);
            p4 = MathHelper.GetRotatedAndMovedPoint(p4, TXRotation, TYRotation, TZRotation, CenterVector);
            p5 = MathHelper.GetRotatedAndMovedPoint(p5, TXRotation, TYRotation, TZRotation, CenterVector);
            p6 = MathHelper.GetRotatedAndMovedPoint(p6, TXRotation, TYRotation, TZRotation, CenterVector);
            p7 = MathHelper.GetRotatedAndMovedPoint(p7, TXRotation, TYRotation, TZRotation, CenterVector);
            p8 = MathHelper.GetRotatedAndMovedPoint(p8, TXRotation, TYRotation, TZRotation, CenterVector);

            //注意这些点的顺序,按顺时针或逆时针,不要乱序
            FaceOne = new PartFace(p1, p2, p8, p7, 1, this);
            FaceTwo = new PartFace(p3, p4, p6, p5, 2, this);
            FaceThree = new PartFace(p1, p2, p4, p3, 3, this);
            FaceFour = new PartFace(p5, p6, p8, p7, 4, this);
            FaceFive = new PartFace(p1, p3, p5, p7, 5, this);
            FaceSix = new PartFace(p2, p4, p6, p8, 6, this);

            Faces.Clear();
            Faces.Add(FaceOne);
            Faces.Add(FaceTwo);
            Faces.Add(FaceThree);
            Faces.Add(FaceFour);
            Faces.Add(FaceFive);
            Faces.Add(FaceSix);
        }
        /// <summary>
        /// 判断点是否嵌入了表面所在的板件
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="peakValue">嵌入板件的深度值,按照设计这个值应当是负值</param>
        /// <param name="associateDist">判定时的容差,为正值</param>
        /// <returns></returns>
        private bool IsDistEnough(PartFace anotherFace, Point3d pt, double peakValue, double associateDist)
        {
            //先把世界坐标系下的pt转换成mp坐标系下
            pt = pt.TransformBy(Matrix3d.AlignCoordinateSystem(anotherFace.Part.MovedMPPoint,
                                                               anotherFace.Part.MovedMPXAxis,
                                                               anotherFace.Part.MovedMPYAxis,
                                                               anotherFace.Part.MovedMPZAxis,
                                                               Point3d.Origin,
                                                               Vector3d.XAxis,
                                                               Vector3d.YAxis,
                                                               Vector3d.ZAxis));

            //取有效数字两个,是为了避免精确计算的情况下的误差导致判断错误
            double z = System.Math.Round(pt.Z, 2);

            //面5和面6的判断不同,这是因为Z的正方向发生了变化
            double zlimitDown = 0 - peakValue;
            double zlimitUp = associateDist - peakValue;

            if (anotherFace.FaceNumber == 6)
            {
                zlimitUp = associateDist + this.Part.Thickness + peakValue;
                zlimitDown = this.Part.Thickness + peakValue;
            }
            if (z >= zlimitDown && z <= zlimitUp)
                return true;
            else return false;
        }
        /// <summary>
        /// 判断当前面是否与某个面相关联
        /// </summary>
        /// <param name="face">判断是否关联的面</param>
        /// <param name="associateDist">容忍值,就是容差</param>
        /// <param name="peakValue">距离值,属于特定的距离判定</param>
        /// <returns></returns>
        internal bool IsAssocaitedWithAnotherFace(PartFace anotherFace, double associateDist, double peakValue)
        {
            /*
            * 判断原则
            * 1、两个面平行且距离小于某个固定值
            * 2、指令面的所有顶点,投影到被关联面,至少有一个点位于关联面的内部
            * 3、如果是开槽关联,则上述两条不适用
            */

            //如果他们是同一个板件的不同面,永远都是不关联的
            if (this.Part == anotherFace.Part)
                return false;

            //如果两个面不平行,那也是不关联的
            //TODO:这里用到了Plane属于CAD的实体,是否会造成内存泄漏?
            if (!anotherFace.Plane.IsParallelTo(this.Plane))
            {
                return false;
            }

            //如果面试四个水平边,也不进行判断,(考虑到开槽、层板孔指令的适用范围)
            if (anotherFace.IsHorizontalFace)
                return false;

            ////不再做距离关联,距离的判断放到点的判断中
            ////如果两个面的距离大于一定距离也就不关联
            //if (anotherFace.Plane.DistanceTo(this.Point1) > dist)
            //{
            //    return false;
            //}

            //需要判断两件事情:
            //1、距离的判断,如嵌入的深度等等
            //2、板件是否嵌入,嵌入一个点还是两个点等等
            if (!IsDistEnough(anotherFace, this.Point1, peakValue, associateDist))
                return false;

            //用using,使用完就销毁掉这些对象
            using (Line line1 = new Line(this.Point1, this.Point4))
            using (Line line2 = new Line(this.Point2, this.Point3))
            using (Line fLine1 = new Line(anotherFace.Point1, anotherFace.Point2))
            using (Line fLine2 = new Line(anotherFace.Point2, anotherFace.Point3))
            using (Line fLine3 = new Line(anotherFace.Point3, anotherFace.Point4))
            using (Line fLine4 = new Line(anotherFace.Point4, anotherFace.Point1))
            {
                using (Line line1Project = line1.GetOrthoProjectedCurve(anotherFace.Plane) as Line)
                using (Line line2Project = line2.GetOrthoProjectedCurve(anotherFace.Plane) as Line)
                {
                    Line[] lines = new Line[] { fLine1, fLine2, fLine3, fLine4 };

                    foreach (Line l in lines)
                    {
                        Point3dCollection pts1 = new Point3dCollection();
                        Point3dCollection pts2 = new Point3dCollection();

                        l.IntersectWith(line1Project, Intersect.OnBothOperands, pts1, IntPtr.Zero, IntPtr.Zero);

                        if (pts1.Count > 0)
                            return true;

                        l.IntersectWith(line2Project, Intersect.OnBothOperands, pts2, IntPtr.Zero, IntPtr.Zero);
                        if (pts2.Count > 0)
                            return true;
                    }
                }
            }

            return false;
        }
Exemple #6
0
        private void SetFaces()
        {
            Point3d p1 = Point3d.Origin;
            Point3d p2 = Point3d.Origin;
            Point3d p3 = Point3d.Origin;
            Point3d p4 = Point3d.Origin;
            Point3d p5 = Point3d.Origin;
            Point3d p6 = Point3d.Origin;
            Point3d p7 = Point3d.Origin;
            Point3d p8 = Point3d.Origin;

            if (!this.MachinePoint.IsRotated)
            {
                p1 = new Point3d(0, 0, 0);
                p2 = new Point3d(0, 0, Thickness);
                p3 = new Point3d(0, Width, 0);
                p4 = new Point3d(0, Width, Thickness);
                p5 = new Point3d(Length, Width, 0);
                p6 = new Point3d(Length, Width, Thickness);
                p7 = new Point3d(Length, 0, 0);
                p8 = new Point3d(Length, 0, Thickness);
            }
            else
            {
                p1 = new Point3d(0, 0, 0);
                p2 = new Point3d(0, 0, Thickness);
                p3 = new Point3d(0, Length, 0);
                p4 = new Point3d(0, Length, Thickness);
                p5 = new Point3d(Width, Length, 0);
                p6 = new Point3d(Width, Length, Thickness);
                p7 = new Point3d(Width, 0, 0);
                p8 = new Point3d(Width, 0, Thickness);
            }

            //将p1-p8从MP坐标系转换成为世界坐标系下的坐标
            p1 = p1.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p2 = p2.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p3 = p3.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p4 = p4.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p5 = p5.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p6 = p6.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p7 = p7.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p8 = p8.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, MPPoint, MPXAxis, MPYAxis, MPZAxis));
            p1 = MathHelper.GetRotatedAndMovedPoint(p1, TXRotation, TYRotation, TZRotation, CenterVector);
            p2 = MathHelper.GetRotatedAndMovedPoint(p2, TXRotation, TYRotation, TZRotation, CenterVector);
            p3 = MathHelper.GetRotatedAndMovedPoint(p3, TXRotation, TYRotation, TZRotation, CenterVector);
            p4 = MathHelper.GetRotatedAndMovedPoint(p4, TXRotation, TYRotation, TZRotation, CenterVector);
            p5 = MathHelper.GetRotatedAndMovedPoint(p5, TXRotation, TYRotation, TZRotation, CenterVector);
            p6 = MathHelper.GetRotatedAndMovedPoint(p6, TXRotation, TYRotation, TZRotation, CenterVector);
            p7 = MathHelper.GetRotatedAndMovedPoint(p7, TXRotation, TYRotation, TZRotation, CenterVector);
            p8 = MathHelper.GetRotatedAndMovedPoint(p8, TXRotation, TYRotation, TZRotation, CenterVector);

            //注意这些点的顺序,按顺时针或逆时针,不要乱序
            FaceOne   = new PartFace(p1, p2, p8, p7, 1, this);
            FaceTwo   = new PartFace(p3, p4, p6, p5, 2, this);
            FaceThree = new PartFace(p1, p2, p4, p3, 3, this);
            FaceFour  = new PartFace(p5, p6, p8, p7, 4, this);
            FaceFive  = new PartFace(p1, p3, p5, p7, 5, this);
            FaceSix   = new PartFace(p2, p4, p6, p8, 6, this);

            Faces.Clear();
            Faces.Add(FaceOne);
            Faces.Add(FaceTwo);
            Faces.Add(FaceThree);
            Faces.Add(FaceFour);
            Faces.Add(FaceFive);
            Faces.Add(FaceSix);
        }
Exemple #7
0
        }                               //面所在的CAD平面,用于一些面的关系的判断,如平行、距离

        /// <summary>
        ///
        /// </summary>
        /// <param name="anotherFace"></param>
        /// <param name="dist">容忍距离值,包含容差,通常为1</param>
        /// <param name="IsDado">是否为开槽类的关联机加工</param>
        /// <returns></returns>
        public bool IsAssocaitedWithAnotherFace(PartFace anotherFace, double dist)
        {
            /*
             * 判断原则
             * 1、两个面平行且距离小于某个固定值
             * 2A、指令面的所有顶点,投影到被关联面,至少有一个点位于关联面的内部
             * 2B、(改进算法)指令面的两个对角点,如果投影后都在另一个面内部,则认为是关联的,
             *     如果不是都在则有可能一个或两个都不在内部
             *     做一条线段链接起来,和另一面的四条边做交点
             *     如果有一个交点则是关联的
             * 3、如果是开槽关联,则上述两条不适用
             */

            //如果他们是同一个板件的不同面,永远都是不关联的
            if (this.Part == anotherFace.Part)
            {
                return(false);
            }

            //如果两个面不平行,那也是不关联的
            //TODO:这里用到了Plane属于CAD的实体,是否会造成内存泄漏?
            if (!anotherFace.Plane.IsParallelTo(this.Plane))
            {
                return(false);
            }

            //如果两个面的距离大于一定距离也就不关联
            if (anotherFace.Plane.DistanceTo(this.Point1) > dist)
            {
                return(false);
            }

            //如果是开槽这样的关联,就需要注意的:
            //1、两个板件得有交集
            //2、距离值较大
            //3、嵌入值如何界定?

            //计算所在面的四个点,共有几个点落在另一个面的板件范围内
            int PtInPartsCount = this.Points.Count(pt => anotherFace.IsPointIn(pt, dist));

            //对于所关联的面是面5、面6或者是4个边,对点的数量要求也不同
            if (anotherFace.IsHorizontalFace && PtInPartsCount == 4)
            {
                return(true);
            }
            else if (!anotherFace.IsHorizontalFace)
            {
                if (PtInPartsCount <= 2)
                {
                    //对于没有一个点在内部的情况,要判断对角线与板件四边的投影线是否有交点
                    return(anotherFace.IsLineCrossBorder(this.Point1, this.Point3));
                }
                else
                {
                    //三个以上的,就必然了
                    return(true);
                }
            }

            return(false);
        }
Exemple #8
0
        /// <summary>
        /// 判断当前面是否与某个面相关联
        /// </summary>
        /// <param name="face">判断是否关联的面</param>
        /// <param name="associateDist">容忍值,就是容差</param>
        /// <param name="peakValue">距离值,属于特定的距离判定</param>
        /// <returns></returns>
        internal bool IsAssocaitedWithAnotherFace(PartFace anotherFace, double associateDist, double peakValue)
        {
            /*
             * 判断原则
             * 1、两个面平行且距离小于某个固定值
             * 2、指令面的所有顶点,投影到被关联面,至少有一个点位于关联面的内部
             * 3、如果是开槽关联,则上述两条不适用
             */

            //如果他们是同一个板件的不同面,永远都是不关联的
            if (this.Part == anotherFace.Part)
            {
                return(false);
            }

            //如果两个面不平行,那也是不关联的
            //TODO:这里用到了Plane属于CAD的实体,是否会造成内存泄漏?
            if (!anotherFace.Plane.IsParallelTo(this.Plane))
            {
                return(false);
            }

            //如果面试四个水平边,也不进行判断,(考虑到开槽、层板孔指令的适用范围)
            if (anotherFace.IsHorizontalFace)
            {
                return(false);
            }

            ////不再做距离关联,距离的判断放到点的判断中
            ////如果两个面的距离大于一定距离也就不关联
            //if (anotherFace.Plane.DistanceTo(this.Point1) > dist)
            //{
            //    return false;
            //}

            //需要判断两件事情:
            //1、距离的判断,如嵌入的深度等等
            //2、板件是否嵌入,嵌入一个点还是两个点等等
            if (!IsDistEnough(anotherFace, this.Point1, peakValue, associateDist))
            {
                return(false);
            }

            //用using,使用完就销毁掉这些对象
            using (Line line1 = new Line(this.Point1, this.Point4))
                using (Line line2 = new Line(this.Point2, this.Point3))
                    using (Line fLine1 = new Line(anotherFace.Point1, anotherFace.Point2))
                        using (Line fLine2 = new Line(anotherFace.Point2, anotherFace.Point3))
                            using (Line fLine3 = new Line(anotherFace.Point3, anotherFace.Point4))
                                using (Line fLine4 = new Line(anotherFace.Point4, anotherFace.Point1))
                                {
                                    using (Line line1Project = line1.GetOrthoProjectedCurve(anotherFace.Plane) as Line)
                                        using (Line line2Project = line2.GetOrthoProjectedCurve(anotherFace.Plane) as Line)
                                        {
                                            Line[] lines = new Line[] { fLine1, fLine2, fLine3, fLine4 };

                                            foreach (Line l in lines)
                                            {
                                                Point3dCollection pts1 = new Point3dCollection();
                                                Point3dCollection pts2 = new Point3dCollection();

                                                l.IntersectWith(line1Project, Intersect.OnBothOperands, pts1, IntPtr.Zero, IntPtr.Zero);

                                                if (pts1.Count > 0)
                                                {
                                                    return(true);
                                                }

                                                l.IntersectWith(line2Project, Intersect.OnBothOperands, pts2, IntPtr.Zero, IntPtr.Zero);
                                                if (pts2.Count > 0)
                                                {
                                                    return(true);
                                                }
                                            }
                                        }
                                }

            return(false);
        }