示例#1
0
        public static Vector2f Projection(this Vector2f obj, Vector2f vector)
        {
            float vectorLen = vector.Len();
            float len       = obj.Dot(vector) / vectorLen;

            return(vector / vectorLen * len);
        }
示例#2
0
        protected void PopulateNewDomainPoints2()
        {
            List <Vector2f> domainPointsCopy = new List <Vector2f>();

            for (int i = 0; i < this.domainPoints.Count; i++)
            {
                Vector2f firstPoint;
                if (i == 0)
                {
                    firstPoint = this.domainPoints[this.domainPoints.Count - 1];
                }
                else
                {
                    firstPoint = this.domainPoints[i - 1];
                }
                Vector2f secondPoint = this.domainPoints[i];
                Vector2f thirdPoint  = this.domainPoints[(i + 1) % this.domainPoints.Count];
                Vector2f fourthPoint = this.domainPoints[(i + 2) % this.domainPoints.Count];

                Vector2f normVector1 = secondPoint - firstPoint;
                normVector1 = normVector1 / normVector1.Len();

                Vector2f normVector2 = thirdPoint - secondPoint;
                normVector2 = normVector2 / normVector2.Len();

                Vector2f normVector3 = fourthPoint - thirdPoint;
                normVector3 = normVector3 / normVector3.Len();

                float distX1 = normVector1.X != 0 ? (secondPoint.X - firstPoint.X) / normVector1.X : (secondPoint.Y - firstPoint.Y) / normVector1.Y;
                float distX2 = normVector2.X != 0 ? distX1 + (thirdPoint.X - secondPoint.X) / normVector2.X : distX1 + (thirdPoint.Y - secondPoint.Y) / normVector2.Y;
                float distX3 = normVector3.X != 0 ? distX2 + (fourthPoint.X - thirdPoint.X) / normVector3.X : distX2 + (fourthPoint.Y - thirdPoint.Y) / normVector3.Y;

                Vector2f firstPointX  = new Vector2f(0, firstPoint.X);
                Vector2f secondPointX = new Vector2f(distX1, secondPoint.X);
                Vector2f thirdPointX  = new Vector2f(distX2, thirdPoint.X);
                Vector2f fourthPointX = new Vector2f(distX3, fourthPoint.X);

                float x         = (distX2 + distX1) / 2;
                float newPointX = this.CubicInterpolate(x, firstPointX, secondPointX, thirdPointX, fourthPointX);

                Vector2f firstPointY  = new Vector2f(0, firstPoint.Y);
                Vector2f secondPointY = new Vector2f(distX1, secondPoint.Y);
                Vector2f thirdPointY  = new Vector2f(distX2, thirdPoint.Y);
                Vector2f fourthPointY = new Vector2f(distX3, fourthPoint.Y);

                float newPointY = this.CubicInterpolate(x, firstPointY, secondPointY, thirdPointY, fourthPointY);

                domainPointsCopy.Add(this.domainPoints[i]);
                domainPointsCopy.Add(new Vector2f(newPointX, newPointY));
            }

            this.domainPoints = domainPointsCopy;
        }
示例#3
0
        private void UpdateCenter()
        {
            Vector2f offsetVector = this.StarTo.Position - this.StarFrom.Position;
            float    offsetLen    = offsetVector.Len();
            float    adjSide      = offsetLen / 2;

            double angle = Math.Acos(adjSide / Math.Abs(this.Radius)) * Math.Sign(this.Radius);

            Vector2f toCenter = offsetVector.Rotate(angle);

            toCenter = toCenter * this.Radius / offsetLen;

            this.Center = this.StarFrom.Position + toCenter;
        }
示例#4
0
        public static float Angle(this Vector2f obj)
        {
            double len  = obj.Len();
            double acos = Math.Acos(obj.X / len);

            float result = 0;

            if (obj.Y >= 0)
            {
                result = (float)acos;
            }
            else
            {
                result = (float)((Math.PI - acos) + Math.PI);
            }

            return((float)(result * 180 / Math.PI));
        }
示例#5
0
        protected void PopulateNewDomainPoints()
        {
            List <Vector2f> domainPointsCopy = new List <Vector2f>();

            for (int i = 0; i < this.domainPoints.Count; i++)
            {
                Vector2f firstPoint  = this.domainPoints[i];
                Vector2f secondPoint = this.domainPoints[(i + 1) % this.domainPoints.Count];
                Vector2f thirdPoint  = this.domainPoints[(i + 2) % this.domainPoints.Count];

                Vector2f normVector1 = secondPoint - firstPoint;
                normVector1 = normVector1 / normVector1.Len();

                Vector2f normVector2 = thirdPoint - secondPoint;
                normVector2 = normVector2 / normVector2.Len();

                float distX1 = normVector1.X != 0 ? (secondPoint.X - firstPoint.X) / normVector1.X : (secondPoint.Y - firstPoint.Y) / normVector1.Y;
                float distX2 = normVector2.X != 0 ? distX1 + (thirdPoint.X - secondPoint.X) / normVector2.X : distX1 + (thirdPoint.Y - secondPoint.Y) / normVector2.Y;

                Vector2f firstPointX  = new Vector2f(0, firstPoint.X);
                Vector2f secondPointX = new Vector2f(distX1, secondPoint.X);
                Vector2f thirdPointX  = new Vector2f(distX2, thirdPoint.X);

                float x         = distX1 / 2;
                float newPointX = this.QuadraticInterpolate(x, firstPointX, secondPointX, thirdPointX);

                Vector2f firstPointY  = new Vector2f(0, firstPoint.Y);
                Vector2f secondPointY = new Vector2f(distX1, secondPoint.Y);
                Vector2f thirdPointY  = new Vector2f(distX2, thirdPoint.Y);

                float newPointY = this.QuadraticInterpolate(x, firstPointY, secondPointY, thirdPointY);

                domainPointsCopy.Add(this.domainPoints[i]);
                domainPointsCopy.Add(new Vector2f(newPointX, newPointY));
            }

            this.domainPoints = domainPointsCopy;
        }
示例#6
0
 public static Vector2f Normalize(this Vector2f obj)
 {
     return(obj / obj.Len());
 }
示例#7
0
        private bool IsPointInsideDomain(Vector2f coordinate)
        {
            bool result = false;

            Vector2f origin = new Vector2f(-100000, -100000);

            float minDist = int.MaxValue;

            int nbIntersect = 0;

            for (int i = 0; i < this.domainPoints.Count; i++)
            {
                Vector2f point1 = this.domainPoints[i];
                Vector2f point2;
                if (i == this.domainPoints.Count - 1)
                {
                    point2 = this.domainPoints[0];
                }
                else
                {
                    point2 = this.domainPoints[i + 1];
                }

                float num1  = point1.X * point2.Y - point1.Y * point2.X;
                float num2  = origin.X * coordinate.Y - origin.Y * coordinate.X;
                float denum = (point1.X - point2.X) * (origin.Y - coordinate.Y) - (point1.Y - point2.Y) * (origin.X - coordinate.X);

                if (denum != 0)
                {
                    float intersecX = (num1 * (origin.X - coordinate.X) - num2 * (point1.X - point2.X)) / denum;
                    float intersecY = (num1 * (origin.Y - coordinate.Y) - num2 * (point1.Y - point2.Y)) / denum;

                    Vector2f intersect = new Vector2f(intersecX, intersecY);

                    if (intersect != point2 &&
                        (intersect - point1).Dot(intersect - point2) < 0 &&
                        (intersect - origin).Dot(intersect - coordinate) < 0)
                    {
                        nbIntersect++;
                    }
                }

                Vector2f firstVector = coordinate - point1;

                Vector2f normalizedEdge = (point2 - point1).Normalize();
                //vec2 vector = vector - normalizedEdge * dot(normalizedEdge, vector);

                //vec3 crossVector = cross(vec3(firstVector, 0), vec3(normalizedEdge, 0));
                //vec3 crossVector2 = cross(vec3(vector2, 0), vec3(-normalizedEdge, 0));

                Vector2f secondVector = coordinate - point2;
                if (normalizedEdge.Dot(firstVector) * normalizedEdge.Dot(secondVector) < 0)
                {
                    float crossLen = Math.Abs(firstVector.CrossZ(normalizedEdge));

                    if (crossLen < minDist)
                    {
                        minDist = crossLen;
                    }
                }

                float lenToPoint = firstVector.Len();
                if (lenToPoint < minDist)
                {
                    minDist = lenToPoint;
                }
            }

            if (this.isFilled)
            {
                if (nbIntersect % 2 == 1)
                {
                    result = true;
                }
            }

            if (minDist < MARGIN_DOMAIN / 2)
            {
                result = true;
            }

            return(result);
        }
示例#8
0
        private List <Vector2f> PopulateNewDomainPoints3(CJStarDomain entity)
        {
            List <Vector2f> pointsToReturn = new List <Vector2f>();

            for (int i = 0; i < entity.Domain.Count; i++)
            {
                StarEntity currentStarEntity = entity.Domain[i];
                StarEntity nextStarEntity    = entity.Domain[(i + 1) % entity.Domain.Count];

                pointsToReturn.Add(currentStarEntity.Position);

                if (entity.DomainLinks.TryGetValue(currentStarEntity, out StarLinkEntity currentLink) && currentLink is CurvedStarLinkEntity)
                {
                    int sign = currentLink.StarFrom == currentStarEntity ? 1 : -1;

                    float radiusLink = (currentLink as CurvedStarLinkEntity).Radius * sign;

                    Vector2f currentToNextNorm = nextStarEntity.Position - currentStarEntity.Position;
                    float    lenCurrentToNext  = currentToNextNorm.Len();
                    currentToNextNorm = currentToNextNorm / lenCurrentToNext;

                    float angleToRotate = (float)Math.Acos(lenCurrentToNext / (2 * radiusLink));

                    Vector2f currentToCenter = currentToNextNorm.Rotate(angleToRotate) * radiusLink;
                    Vector2f centerPoint     = currentStarEntity.Position + currentToCenter;

                    Vector2f newPoint = centerPoint + (-currentToCenter).Rotate(Math.Sign(radiusLink) * sign * (Math.PI / 2 - angleToRotate));

                    pointsToReturn.Add(newPoint);
                }
                else
                {
                    Vector2f firstPoint;
                    if (i == 0)
                    {
                        firstPoint = entity.Domain[entity.Domain.Count - 1].Position;
                    }
                    else
                    {
                        firstPoint = entity.Domain[i - 1].Position;
                    }
                    Vector2f secondPoint = entity.Domain[i].Position;
                    Vector2f thirdPoint  = entity.Domain[(i + 1) % entity.Domain.Count].Position;
                    Vector2f fourthPoint = entity.Domain[(i + 2) % entity.Domain.Count].Position;

                    Vector2f normVector1 = secondPoint - firstPoint;
                    normVector1 = normVector1 / normVector1.Len();

                    Vector2f normVector2 = thirdPoint - secondPoint;
                    normVector2 = normVector2 / normVector2.Len();

                    Vector2f normVector3 = fourthPoint - thirdPoint;
                    normVector3 = normVector3 / normVector3.Len();

                    float distX1 = normVector1.X != 0 ? (secondPoint.X - firstPoint.X) / normVector1.X : (secondPoint.Y - firstPoint.Y) / normVector1.Y;
                    float distX2 = normVector2.X != 0 ? distX1 + (thirdPoint.X - secondPoint.X) / normVector2.X : distX1 + (thirdPoint.Y - secondPoint.Y) / normVector2.Y;
                    float distX3 = normVector3.X != 0 ? distX2 + (fourthPoint.X - thirdPoint.X) / normVector3.X : distX2 + (fourthPoint.Y - thirdPoint.Y) / normVector3.Y;

                    Vector2f firstPointX  = new Vector2f(0, firstPoint.X);
                    Vector2f secondPointX = new Vector2f(distX1, secondPoint.X);
                    Vector2f thirdPointX  = new Vector2f(distX2, thirdPoint.X);
                    Vector2f fourthPointX = new Vector2f(distX3, fourthPoint.X);

                    float x         = (distX2 + distX1) / 2;
                    float newPointX = this.CubicInterpolate(x, firstPointX, secondPointX, thirdPointX, fourthPointX);

                    Vector2f firstPointY  = new Vector2f(0, firstPoint.Y);
                    Vector2f secondPointY = new Vector2f(distX1, secondPoint.Y);
                    Vector2f thirdPointY  = new Vector2f(distX2, thirdPoint.Y);
                    Vector2f fourthPointY = new Vector2f(distX3, fourthPoint.Y);

                    float newPointY = this.CubicInterpolate(x, firstPointY, secondPointY, thirdPointY, fourthPointY);

                    pointsToReturn.Add(new Vector2f(newPointX, newPointY));
                }
            }

            return(pointsToReturn);
        }