public bool InPlanePolygon2d(MyVector2 p)
        {
            this.ProjectVerticesTo2d();

            if (this.planeVertices.Count == 0)
            {
                return(false);
            }
            double    theta = 0;
            MyVector2 v1    = p - planeVertices2d[0];
            MyVector2 v2    = p - planeVertices2d[planeVertices2d.Count - 1];

            theta = Math.Acos(v1.Dot(v2) / (v1.Length() * v2.Length()));
            for (int i = 0; i < planeVertices.Count - 1; i++)
            {
                v1     = p - planeVertices2d[i];
                v2     = p - planeVertices2d[i + 1];
                theta += Math.Acos(v1.Dot(v2) / (v1.Length() * v2.Length()));
            }

            if (Math.Abs(2 * Math.PI - theta) < 1e-10)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        private MyVector3 MapToSphere(MyVector2 pt)
        {
            #region old map
            //MyVector2 v = new MyVector2();
            ////v.x = (w - pt.x) * adjustWidth;
            //v.x = (pt.x - this.w) * adjustWidth;
            //v.y = (this.h - pt.y) * adjustHeight;

            //double lenSq = v.Dot(v);
            //MyVector3 v3 = new MyVector3(v.x, 0, v.y);
            //if (lenSq > 1.0)
            //{
            //    double norm = 1.0 / Math.Sqrt(lenSq);
            //    return new MyVector3(v.x * norm, -v.y * norm, 0);
            //}
            //else
            //{
            //    return new MyVector3(v.x, Math.Sqrt(1.0 - lenSq), v.y);
            //}
            #endregion

            //just. 1116
            MyVector2 v = new MyVector2();
            v.x = (this.w - pt.x) * adjustWidth / radius;
            v.y = (this.h - pt.y) * adjustHeight / radius;

            double lenSq = v.Dot(v);
            //MyVector3 v3 = new MyVector3(v.x, 0, v.y);
            if (lenSq > 1.0)
            {
                double norm = 1.0 / Math.Sqrt(lenSq);
                return(new MyVector3(v.x * norm, v.y * norm, 0));
            }
            else
            {
                return(new MyVector3(v.x, v.y, Math.Sqrt(1.0 - lenSq)));
            }
        }