private bool IsPointInZoneCore(CalcInput c)
        {
            // http://alienryderflex.com/polygon/

            double lat   = c.MainPoint.Lat;
            double lon   = c.MainPoint.Lon;
            int    count = c.TargetZonePointCount;

            int  j        = count - 1;
            bool oddNodes = false;

            Point  iPt, jPt;
            double iLat, iLon, jLat, jLon;

            for (int i = 0; i < count; i++)
            {
                jPt  = c.TargetZonePoints[j];
                jLat = jPt.Lat;
                jLon = jPt.Lon;
                iPt  = c.TargetZonePoints[i];
                iLat = iPt.Lat;
                iLon = iPt.Lon;

                if ((iLat < lat && jLat >= lat || jLat < lat && iLat >= lat) && (iLon <= lon || jLon <= lon))
                {
                    oddNodes ^= (iLon + (lat - iLat) / (jLat - iLat) * (jLon - iLon) < lon);
                }
                j = i;
            }

            return(oddNodes);
        }
        private Vector VectorToPointCore(CalcInput c)
        {
            // http://www.movable-type.co.uk/scripts/latlong.html#ortho-dist

            double lat1 = c.MainPoint.Lat * PI_180;
            double lon1 = c.MainPoint.Lon * PI_180;
            double lat2 = c.TargetPoint.Lat * PI_180;
            double lon2 = c.TargetPoint.Lon * PI_180;

            double cosLat1 = Math.Cos(lat1);
            double cosLat2 = Math.Cos(lat2);

            double dLat = lat2 - lat1;
            double dLon = lon2 - lon1;

            double hvsLat = Math.Sin(dLat / 2);
            double hvsLon = Math.Sin(dLon / 2);

            double a = (hvsLat * hvsLat) + (hvsLon * hvsLon * cosLat1 * cosLat2);

            double cc = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

            double distance = EARTH_RADIUS * cc;

            // http://www.movable-type.co.uk/scripts/latlong.html#bearing

            double bearing = Math.Atan2(
                Math.Sin(dLon) * cosLat2,
                cosLat1 * Math.Sin(lat2) - Math.Sin(lat1) * cosLat2 * Math.Cos(dLon)
                ) / PI_180;

            return(new Vector(distance, bearing));
        }
        public ZonePoint[] GetCircle(ZonePoint center, double radius, int points)
        {
            // Sanity check.
            if (points < 3)
            {
                throw new ArgumentOutOfRangeException("points", "Cannot compute a circle with fewer than 3 points.");
            }

            // Computes the input.
            CalcInput c = new CalcInput();

            c.MainPoint    = new Point(center);
            c.TargetVector = new Vector(radius, null);

            // For each needed point, translate the center "radius meters"
            // towards "i * 360/points".
            ZonePoint[] pts  = new ZonePoint[points];
            double      step = 360d / points;

            for (int i = 0; i < points; i++)
            {
                c.TargetVector.Bearing = step * i;
                pts[i] = TranslatePointCore(c).ToZonePoint(_dataFactory);
            }

            return(pts);
        }
Exemple #4
0
    private void Initialize()
    {
        calcInput        = connectedMenus.calcInput;
        boundsManager    = connectedMenus.boundsManager;
        pieceWiseControl = connectedMenus.pieceWiseControl;
        boundsManager    = connectedMenus.boundsManager;
        saveLoadMenu     = connectedMenus.saveLoadMenu;

        if (connectedMenus.boundsManager != null)
        {
            connectedMenus.boundsManager.Initialize(this);
        }
        connectedMenus.calcInput.Initialize(this);
        //tier 3
        connectedMenus.outputMenu.Initialize(this);

        //Req: calcInput
        connectedMenus.pieceWiseControl.Initialize(this);
        //Req: calcInput
        calcInput.ChangeOutput(expressionSet.expressions[X]);
        //Req: calcInput
        connectedMenus.presetMenu.Initialize(this);

        connectedMenus.saveLoadMenu.Initialize(this);

        if (connectedMenus.particleAnimationSettings != null)
        {
            connectedMenus.particleAnimationSettings.Initialize(this);
        }
    }
        public ActionResult GetMessage(string culture)
        {
            var inputObject  = new CalcInput(expression: string.Empty, culture: new CultureInfo(culture));
            var resultObject = inputObject.ExecuteExpression();
            var example      = $"7{resultObject.Separator}3 + p^(8{resultObject.Separator}4)";

            return(Content($"Hi! Type smth like this: " + example));
        }
        public bool IsPointInZone(ZonePoint point, Zone target)
        {
            // Computes the calculation input.
            CalcInput c = new CalcInput();

            c.MainPoint = new Point(point);
            c.SetTargetZone(target);

            return(IsPointInZoneCore(c));
        }
Exemple #7
0
    public void Initialize()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        calcInput        = connectedMenus.calcInput;
        boundsManager    = connectedMenus.boundsManager;
        pieceWiseControl = connectedMenus.pieceWiseControl;
        boundsManager    = connectedMenus.boundsManager;
        saveLoadMenu     = connectedMenus.saveLoadMenu;
        tournamentMenu   = connectedMenus.tournamentMenu;
        submissionsMenu  = connectedMenus.submissionsMenu;

        if (connectedMenus.boundsManager != null)
        {
            connectedMenus.boundsManager.Initialize(this);
        }
        connectedMenus.calcInput.Initialize(this);
        //tier 3
        connectedMenus.outputMenu.Initialize(this);

        //Req: calcInput
        connectedMenus.pieceWiseControl.Initialize(this);
        //Req: calcInput
        calcInput.ChangeOutput(expressionSet.expressions["X"]);
        //Req: calcInput
        connectedMenus.presetMenu.Initialize(this);

        connectedMenus.saveLoadMenu.Initialize(this);

        if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.Equals("3 - FreeParametrization"))
        {
            if (connectedMenus.tournamentMenu != null)
            {
                connectedMenus.tournamentMenu.Initialize(this);
            }

            if (connectedMenus.submissionsMenu != null)
            {
                connectedMenus.submissionsMenu.Initialize(this);
            }

            if (connectedMenus.mySubmissionsMenu != null)
            {
                connectedMenus.mySubmissionsMenu.Initialize(this);
            }
        }

        if (connectedMenus.particleAnimationSettings != null)
        {
            connectedMenus.particleAnimationSettings.Initialize(this);
        }
    }
        private Point TranslatePointCore(CalcInput c)
        {
            double lat  = c.MainPoint.Lat;
            double lon  = c.MainPoint.Lon;
            double dist = c.TargetVector.Distance.Value;

            double rad = AzimuthToAngle(c.TargetVector.Bearing.GetValueOrDefault());
            double x   = MetersToLatitude(dist * Math.Sin(rad));
            double y   = MetersToLongitude(lat, dist * Math.Cos(rad));

            return(new Point(lat + x, lon + y));
        }
        public ZonePoint TranslatePoint(ZonePoint point, LocationVector vector)
        {
            // Computes the input.
            CalcInput c = new CalcInput();

            c.MainPoint    = new Point(point);
            c.TargetVector = new Vector(vector);

            // Performs the computation.
            Point newPoint = TranslatePointCore(c);

            // Returns the right object.
            return(newPoint.ToZonePoint(_dataFactory));
        }
        public LocationVector VectorToPoint(ZonePoint point, ZonePoint target)
        {
            // Computes the input.
            CalcInput c = new CalcInput();

            c.MainPoint   = new Point(point);
            c.TargetPoint = new Point(target);

            // Performs the computation.
            Vector vector = VectorToPointCore(c);

            // Returns the right object.
            return(vector.ToLocationVector(_dataFactory));
        }
        public LocationVector VectorToSegment(ZonePoint point, ZonePoint segmentStartPoint, ZonePoint segmentEndPoint)
        {
            // Computes the input.
            CalcInput c = new CalcInput();

            c.MainPoint     = new Point(point);
            c.SegmentPoint1 = new Point(segmentStartPoint);
            c.SegmentPoint2 = new Point(segmentEndPoint);

            // Performs the computation.
            Vector vector = VectorToSegmentCore(c);

            // Returns the right object.
            return(vector.ToLocationVector(_dataFactory));
        }
        private Vector VectorToSegmentCore(CalcInput c)
        {
            // http://www.movable-type.co.uk/scripts/latlong.html#crossTrack

            Point mainPoint       = c.MainPoint;
            Point firstLinePoint  = c.SegmentPoint1;
            Point secondLinePoint = c.SegmentPoint2;

            c.MainPoint   = firstLinePoint;
            c.TargetPoint = mainPoint;
            Vector d1  = VectorToPointCore(c);
            double b1  = d1.Bearing.GetValueOrDefault();
            double dd1 = PI_180 * MetersToNauticalMiles(d1.Distance.Value) / 60;             // 1 nmi ~= 1'arc

            c.MainPoint   = firstLinePoint;
            c.TargetPoint = secondLinePoint;
            Vector ds  = VectorToPointCore(c);
            double bs  = ds.Bearing.GetValueOrDefault();
            double dds = PI_180 * MetersToNauticalMiles(ds.Distance.Value) / 60;             // 1 nmi ~= 1'arc

            var dist = Math.Asin(Math.Sin(dd1) * Math.Sin(PI_180 * (b1 - bs)));
            var dat  = Math.Acos(Math.Cos(dd1) / Math.Cos(dist));

            c.MainPoint = mainPoint;
            if (dat <= 0)
            {
                c.TargetPoint = firstLinePoint;
                return(VectorToPointCore(c));
            }
            else if (dat >= dds)
            {
                c.TargetPoint = secondLinePoint;
                return(VectorToPointCore(c));
            }

            c.MainPoint    = firstLinePoint;
            c.TargetVector = new Vector(NauticalMilesToMeters(dat * 60 / PI_180), bs);
            Point intersect = TranslatePointCore(c);

            c.MainPoint   = mainPoint;
            c.TargetPoint = intersect;
            return(VectorToPointCore(c));
        }
        private Vector VectorToZoneCore(CalcInput c)
        {
            // If the point is in the zone, the distance and bearing are 0.
            if (IsPointInZoneCore(c))
            {
                return(new Vector(0d, 0d));
            }

            // If the zone doesn't have points, the distance and bearing are null.
            if (c.TargetZonePointCount == 0)
            {
                return(new Vector());
            }

            // Computes the minimal distance to the Zone's edges.
            c.SegmentPoint1 = c.TargetZonePoints.Last();
            c.SegmentPoint2 = c.TargetZonePoints.First();
            Vector minVec  = VectorToSegmentCore(c);
            double minDist = minVec.Distance.Value;

            for (int i = 0; i < c.TargetZonePointCount - 1; i++)
            {
                c.SegmentPoint1 = c.TargetZonePoints[i];
                c.SegmentPoint2 = c.TargetZonePoints[i + 1];
                Vector curr     = VectorToSegmentCore(c);
                double currDist = curr.Distance.Value;

                if (currDist < minDist)
                {
                    minVec  = curr;
                    minDist = currDist;
                }
            }

            return(minVec);
        }
		public bool IsPointInZone(ZonePoint point, Zone target)
		{
			// Computes the calculation input.
			CalcInput c = new CalcInput();
			c.MainPoint = new Point(point);
			c.SetTargetZone(target);

			return IsPointInZoneCore(c);
		}
		private bool IsPointInZoneCore(CalcInput c)
		{
			// http://alienryderflex.com/polygon/

			double lat = c.MainPoint.Lat;
			double lon = c.MainPoint.Lon;
			int count = c.TargetZonePointCount;

			int j = count - 1;
			bool oddNodes = false;

			Point iPt, jPt;
			double iLat, iLon, jLat, jLon;
			for (int i = 0; i < count; i++)
			{
				jPt = c.TargetZonePoints[j];
				jLat = jPt.Lat;
				jLon = jPt.Lon;
				iPt = c.TargetZonePoints[i];
				iLat = iPt.Lat;
				iLon = iPt.Lon;

				if ((iLat < lat && jLat >= lat || jLat < lat && iLat >= lat) && (iLon <= lon || jLon <= lon))
				{
					oddNodes ^= (iLon + (lat - iLat) / (jLat - iLat) * (jLon - iLon) < lon);
				}
				j = i;
			}

			return oddNodes;
		}
		private Vector VectorToPointCore(CalcInput c)
		{
			// http://www.movable-type.co.uk/scripts/latlong.html#ortho-dist
			
			double lat1 = c.MainPoint.Lat * PI_180;
			double lon1 = c.MainPoint.Lon * PI_180;
			double lat2 = c.TargetPoint.Lat * PI_180;
			double lon2 = c.TargetPoint.Lon * PI_180;

			double cosLat1 = Math.Cos(lat1);
			double cosLat2 = Math.Cos(lat2);

			double dLat = lat2 - lat1;
			double dLon = lon2 - lon1;

			double hvsLat = Math.Sin(dLat / 2);
			double hvsLon = Math.Sin(dLon / 2);

			double a = (hvsLat * hvsLat) + (hvsLon * hvsLon * cosLat1 * cosLat2);

			double cc = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

			double distance = EARTH_RADIUS * cc;

			// http://www.movable-type.co.uk/scripts/latlong.html#bearing

			double bearing = Math.Atan2(
				Math.Sin(dLon) * cosLat2,
				cosLat1 * Math.Sin(lat2) - Math.Sin(lat1) * cosLat2 * Math.Cos(dLon)
				) / PI_180;

			return new Vector(distance, bearing);
		}
		private Vector VectorToZoneCore(CalcInput c)
		{
			// If the point is in the zone, the distance and bearing are 0.
			if (IsPointInZoneCore(c))
			{
				return new Vector(0d, 0d);
			}

			// If the zone doesn't have points, the distance and bearing are null.
			if (c.TargetZonePointCount == 0)
			{
				return new Vector();
			}

			// Computes the minimal distance to the Zone's edges.
			c.SegmentPoint1 = c.TargetZonePoints.Last();
			c.SegmentPoint2 = c.TargetZonePoints.First();
			Vector minVec = VectorToSegmentCore(c);
			double minDist = minVec.Distance.Value;

			for (int i = 0; i < c.TargetZonePointCount - 1; i++)
			{
				c.SegmentPoint1 = c.TargetZonePoints[i];
				c.SegmentPoint2 = c.TargetZonePoints[i + 1];
				Vector curr = VectorToSegmentCore(c);
				double currDist = curr.Distance.Value;

				if (currDist < minDist)
				{
					minVec = curr;
					minDist = currDist;
				}
			}

			return minVec;
		}
		public LocationVector VectorToSegment(ZonePoint point, ZonePoint segmentStartPoint, ZonePoint segmentEndPoint)
		{
			// Computes the input.
			CalcInput c = new CalcInput();
			c.MainPoint = new Point(point);
			c.SegmentPoint1 = new Point(segmentStartPoint);
			c.SegmentPoint2 = new Point(segmentEndPoint);

			// Performs the computation.
			Vector vector = VectorToSegmentCore(c);

			// Returns the right object.
			return vector.ToLocationVector(_dataFactory);
		}
		private Vector VectorToSegmentCore(CalcInput c)
		{
			// http://www.movable-type.co.uk/scripts/latlong.html#crossTrack
			
			Point mainPoint = c.MainPoint;
			Point firstLinePoint = c.SegmentPoint1;
			Point secondLinePoint = c.SegmentPoint2;

			c.MainPoint = firstLinePoint;
			c.TargetPoint = mainPoint;
			Vector d1 = VectorToPointCore(c);
			double b1 = d1.Bearing.GetValueOrDefault();
			double dd1 = PI_180 * MetersToNauticalMiles(d1.Distance.Value) / 60; // 1 nmi ~= 1'arc

			c.MainPoint = firstLinePoint;
			c.TargetPoint = secondLinePoint;
			Vector ds = VectorToPointCore(c);
			double bs = ds.Bearing.GetValueOrDefault();
			double dds = PI_180 * MetersToNauticalMiles(ds.Distance.Value) / 60; // 1 nmi ~= 1'arc

			var dist = Math.Asin(Math.Sin(dd1) * Math.Sin(PI_180 * (b1 - bs)));
			var dat = Math.Acos(Math.Cos(dd1) / Math.Cos(dist));

			c.MainPoint = mainPoint;
			if (dat <= 0)
			{
				c.TargetPoint = firstLinePoint;
				return VectorToPointCore(c);
			}
			else if (dat >= dds)
			{
				c.TargetPoint = secondLinePoint;
				return VectorToPointCore(c);
			}

			c.MainPoint = firstLinePoint;
			c.TargetVector = new Vector(NauticalMilesToMeters(dat * 60 / PI_180), bs);
			Point intersect = TranslatePointCore(c);

			c.MainPoint = mainPoint;
			c.TargetPoint = intersect;
			return VectorToPointCore(c);
		}
		public ZonePoint[] GetCircle(ZonePoint center, double radius, int points)
		{
			// Sanity check.
			if (points < 3)
			{
				throw new ArgumentOutOfRangeException("points", "Cannot compute a circle with fewer than 3 points.");
			}
			
			// Computes the input.
			CalcInput c = new CalcInput();
			c.MainPoint = new Point(center);
			c.TargetVector = new Vector(radius, null);
			
			// For each needed point, translate the center "radius meters"
			// towards "i * 360/points".
			ZonePoint[] pts = new ZonePoint[points];
			double step = 360d / points;
			for (int i = 0; i < points; i++)
			{
				c.TargetVector.Bearing = step * i;
				pts[i] = TranslatePointCore(c).ToZonePoint(_dataFactory);
			}

			return pts;
		}
		private Point TranslatePointCore(CalcInput c)
		{
			double lat = c.MainPoint.Lat;
			double lon = c.MainPoint.Lon;
			double dist = c.TargetVector.Distance.Value;

			double rad = AzimuthToAngle(c.TargetVector.Bearing.GetValueOrDefault());
			double x = MetersToLatitude(dist * Math.Sin(rad));
			double y = MetersToLongitude(lat, dist * Math.Cos(rad));

			return new Point(lat + x, lon + y);
		}
		public ZonePoint TranslatePoint(ZonePoint point, LocationVector vector)
		{
			// Computes the input.
			CalcInput c = new CalcInput();
			c.MainPoint = new Point(point);
			c.TargetVector = new Vector(vector);

			// Performs the computation.
			Point newPoint = TranslatePointCore(c);

			// Returns the right object.
			return newPoint.ToZonePoint(_dataFactory);
		}
Exemple #23
0
        public HttpResponseMessage Subtract([FromUri] CalcInput input)
        {
            HttpResponseMessage response = Request.CreateResponse();

            return(response);
        }
Exemple #24
0
 internal KeyboardInputResponder(CalcInput calcInput)
 {
     this.calcInput = calcInput;
 }
		public LocationVector VectorToPoint(ZonePoint point, ZonePoint target)
		{
			// Computes the input.
			CalcInput c = new CalcInput();
			c.MainPoint = new Point(point);
			c.TargetPoint = new Point(target);

			// Performs the computation.
			Vector vector = VectorToPointCore(c);

			// Returns the right object.
			return vector.ToLocationVector(_dataFactory);
		}