Beispiel #1
0
        public IPointCyl Translate(IVector3 translation)
        {
            IVector3 ptXYZ      = new Vector3(this);
            IVector3 ptTrans    = ptXYZ.Translate(translation);
            PointCyl ptCylTrans = new PointCyl(ptTrans);

            ptCylTrans.Col = Col;
            return(ptCylTrans);
        }
Beispiel #2
0
        /// <summary>
        /// returns true if infinite ray and arc intersect, stores intersection(s) in result
        /// </summary>
        /// <param name="arcIn"></param>
        /// <param name="lineIn"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public static IntersectionRecord RayArcXYIntersect(Arc arcIn, Line lineIn)
        {
            try
            {
                IntersectionRecord result = new IntersectionRecord();
                Vector3            Point1;
                IntersectionRecord ir = new IntersectionRecord();
                //transform arc and line to center arc at origin
                Arc  arcT  = arcIn.Translate(new Vector3(-1 * arcIn.Center.X, -1 * arcIn.Center.Y, 0));
                Line lineT = lineIn.Translate(new Vector3(-1 * arcIn.Center.X, -1 * arcIn.Center.Y, 0));
                //parameterize line
                double dy = lineT.Point2.Y - lineT.Point1.Y;
                double dx = lineT.Point2.X - lineT.Point1.X;

                //calc quadratic solution
                double a       = Math.Pow(dx, 2) + Math.Pow(dy, 2);
                double b       = 2 * (dx) * (lineT.Point1.X - arcT.Center.X) + 2 * (dy) * (lineT.Point1.Y - arcT.Center.Y);
                double c       = Math.Pow(lineT.Point1.X - arcT.Center.X, 2) + Math.Pow(lineT.Point1.Y - arcT.Center.Y, 2) - Math.Pow(arcT.Radius, 2);
                double discrim = Math.Pow(b, 2) - 4 * a * c;

                if (discrim >= 0)//check solution is real
                {
                    double tPos   = (-b + Math.Sqrt(discrim)) / (2 * a);
                    double tNeg   = (-b - Math.Sqrt(discrim)) / (2 * a);
                    double xpos   = dx * tPos + lineT.Point1.X;
                    double ypos   = dy * tPos + lineT.Point1.Y;
                    double xneg   = dx * tNeg + lineT.Point1.X;
                    double yneg   = dy * tNeg + lineT.Point1.Y;
                    double angneg = Math.Atan2(yneg, xneg);
                    double angpos = Math.Atan2(ypos, xpos);

                    if (angneg < 0)
                    {
                        angneg += 2 * Math.PI;
                    }
                    if (angpos < 0)
                    {
                        angpos += 2 * Math.PI;
                    }

                    //transform point back before returning
                    if ((angneg >= arcT.StartAngleRad) && (angneg <= arcT.EndAngleRad))
                    {
                        Point1            = new Vector3(xneg, yneg, 0);
                        result            = (IntersectionRecord)Point1.Translate(new Vector3(arcIn.Center.X, arcIn.Center.Y, 0.0));
                        result.Intersects = true;
                    }
                    if ((angpos >= arcT.StartAngleRad) && (angpos <= arcT.EndAngleRad))
                    {
                        Point1            = new Vector3(xpos, ypos, 0);
                        result            = (IntersectionRecord)Point1.Translate(new Vector3(arcIn.Center.X, arcIn.Center.Y, 0.0));
                        result.Intersects = true;
                    }
                }
                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }