Exemplo n.º 1
0
        private List <RefPoint> getRefPoints(Trajectory trj)
        {
            if (trj.Count == 0)
            {
                return(null);
            }
            List <RefPoint> refPoints = new List <RefPoint>();

            for (int i = 0; i < trj.Count; ++i)
            {
                MotionVector mv       = trj[i];
                RefPoint     refPoint = null;
                if (mv.e != null)
                {
                    double distance = mv.e.DistOnLine(mv.e.Start.Point, mv.point);
                    refPoint = new RefPoint(mv.t, mv.e, distance);
                }
                else
                {
                    refPoint = new RefPoint(mv.t, mv.point);
                }
                refPoints.Add(refPoint);
            }
            // calcualte the deviation between trj and the ref points
            //String tempFileName = Path.Combine(Constants.TRJ_DIR, "1000099465_short_ref");
            //StreamWriter sw = new StreamWriter(tempFileName);
            //for (int i = 0; i < trj.Count; ++i)
            //{
            //    MotionVector mv = trj[i];
            //    double dev = GeoPoint.GetDistance(mv.point, refPoints[i].Point);
            //    sw.WriteLine("{0},{1},{2},{3},{4}", mv.t, mv.point.Lat, mv.point.Lng, mv.EdgeId, dev);
            //}
            //sw.Close();
            return(refPoints);
        }
Exemplo n.º 2
0
        void ShowValues()
        {
            if (Phone == null)
            {
                return;
            }

            var acc = new MotionVector
            {
                X = Phone.RotationX / 360,
                Y = Phone.RotationY / 360,
                Z = Phone.Rotation / 360,
            };

            // TODO: For gyro, this should be the speed, not present value.
            // We should find a time-based approach to find the correct values.
            var gyro = new MotionVector
            {
                X = Phone.RotationX / 360,
                Y = Phone.RotationY / 360,
                Z = Phone.Rotation / 360,
            };

            AccelerometerInfo.Text($"Accelorometer       X: {acc.X.Round(2)}      Y: {acc.Y.Round(2)}       Z: {acc.Z.Round(2)}");
            GyroscopeInfo.Text($"Gyroscope             X: {gyro.X.Round(2)}      Y: {gyro.Y.Round(2)}       Z: {gyro.Z.Round(2)}");
            CompassInfo.Text($"Compass                Heading: {acc.Z.Round(2)}");
        }
Exemplo n.º 3
0
        //=============================================
        //End reference C1
        //=============================================

        // This method checks to see if the device was shaken by calling WasTheDeviceShaken
        // and if so it clears the text field.
        private void ClearTextField(MotionVector value)
        {
            if (WasTheDeviceShaken(value))
            {
                this.entryField.Text = "";
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Check if the line formed by startIdx.point and endIdx.point can represents internal motion vectors
        /// </summary>
        /// <param name="startIdx"></param>
        /// <param name="endIdx"></param>
        /// <returns></returns>
        private bool canApproximate(int startIdx, int endIdx)
        {
            bool result = true;

            if (endIdx - startIdx <= 1)
            {
                return(result);
            }
            MotionVector start = trj[startIdx], end = trj[endIdx];
            GeoPoint     pStart = start.point, pEnd = end.point;
            double       baseLat, baseLng;

            baseLat = (pEnd.Lat - pStart.Lat) / (end.t - start.t);
            baseLng = (pEnd.Lng - pStart.Lng) / (end.t - start.t);
            for (int i = startIdx + 1; i < endIdx; i++)
            {
                double       lat, lng;
                double       dev2;
                MotionVector middle = trj[i];
                lat  = baseLat * (middle.t - start.t) + pStart.Lat;
                lng  = baseLng * (middle.t - start.t) + pStart.Lng;
                dev2 = GeoPoint.GetDistance2(new GeoPoint(lat, lng), middle.point);
                //Debug.Assert(middle.e != null);
                if (dev2 > maxDev * maxDev)
                {
                    result = false;
                    break;
                }
            }
            return(result);
        }
Exemplo n.º 5
0
            /// <summary>
            /// Event that occurs when a sensor value changes.
            /// </summary>
            /// <param name="sensorEvent">Sensor event</param>
            public void OnSensorChanged(SensorEvent sensorEvent)
            {
                if (sensorEvent.Values.Count == 1)
                {
                    var value = sensorEvent.Values[0];
                    switch (sensorEvent.Sensor.Type)
                    {
                    case AndroidSensorType.Light:
                        _sensors.EmitLightLevel(value);
                        break;
                    }
                }
                // In this case, the sensor is likely a vector.
                else if (sensorEvent.Values.Count == 3)
                {
                    var vector = new MotionVector(sensorEvent.Values[0], sensorEvent.Values[1], sensorEvent.Values[2]);
                    switch (sensorEvent.Sensor.Type)
                    {
                    case AndroidSensorType.Accelerometer:
                        _sensors.EmitAccelerometer(vector);
                        break;

                    case AndroidSensorType.Gyroscope:
                        _sensors.EmitGyroscope(vector);
                        break;

                    case AndroidSensorType.RotationVector:
                        _sensors.EmitDeviceMotion(vector);
                        break;
                    }
                }
            }
Exemplo n.º 6
0
        void IUpdateable.Update(TimeSpan elapsedInFrame)
        {
            FrameStartPosition = ObjectToMove.Position.Copy();

            foreach (var adjuster in MotionAdjusters)
            {
                adjuster.Update(ObjectToMove, MotionVector);
            }


            foreach (var multiplier in MotionMultipliers)
            {
                MotionVector.X.TargetScale = multiplier.GetTargetMod();
                MotionVector.X.DeltaScale  = multiplier.GetDeltaMod();
                MotionVector.Y.TargetScale = multiplier.GetTargetMod();
                MotionVector.Y.DeltaScale  = multiplier.GetDeltaMod();
            }

            MotionVector.Adjust(elapsedInFrame);


            var motion = CurrentMotionPerSecond;

            FrameVelocity = CurrentMotionPerSecond.Scale(elapsedInFrame.TotalSeconds);
            ObjectToMove.Position.Translate(FrameVelocity);
        }
        public static bool IsSimilarPositionTo(this MotionVector positionOne, MotionVector positionTwo)
        {
            var isSimilarX = IsInRange(positionOne.X, positionTwo.X, Deviation.X);
            var isSimilarY = IsInRange(positionOne.Y, positionTwo.Y, Deviation.Y);
            var isSimilarZ = IsInRange(positionOne.Z, positionTwo.Z, Deviation.Z);

            return(isSimilarX && isSimilarY && isSimilarZ);
        }
 private void DeviceMotionOnSensorValueChanged(object sender, SensorValueChangedEventArgs e)
 {
     if (e.SensorType == MotionSensorType.Accelerometer)
     {
         Position = (MotionVector)e.Value;
     }
     NotifySubscribers();
 }
Exemplo n.º 9
0
        public bool NoMoveInStartNeighbors(MotionVector confusedVector)
        {
            var sourceRoom = GetSourceRoom(confusedVector);
            var endRoom    = this[confusedVector.EndPoint];

            var startNeighbors = _neighbors[sourceRoom].ToList().AddChained(sourceRoom).RemoveChained(endRoom);

            return(startNeighbors.All(n => n.LastMotion.Time.GetValueOrDefault() <= confusedVector.StartTime));
        }
 static MotionVectorExtensions()
 {
     Deviation = new MotionVector
     {
         X = 1,
         Y = 1,
         Z = 1
     };
 }
Exemplo n.º 11
0
        void AccelSensorValueChanged(object sender, SensorValueChangedEventArgs e)
        {
            if (e.SensorType == MotionSensorType.Accelerometer)
            {
                deviceMotion = FixAccelerometerRelative((MotionVector)e.Value);

                #if DEBUG
                Debug.WriteLine("X: {0}, Y: {1}, Z{2}", deviceMotion.X, deviceMotion.Y, deviceMotion.Z);
                #endif
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Get confusion point from all neighbors
        /// </summary>
        /// <param name="vector"></param>
        /// <returns></returns>
        public IList <MotionPoint> GetConfusingPoints(MotionVector vector)
        {
            var targetRoom = GetTargetRoom(vector);

            return(_neighbors[targetRoom].ToList()
                   .AddChained(targetRoom)
                   .Where(room => room.Uid != vector.StartPoint)
                   .Select(room => room.GetConfusion(vector.EndTime))
                   .Where(y => y != MotionPoint.Empty)
                   .ToList());
        }
Exemplo n.º 13
0
 void limitsTest(MotionVector motionVector)
 {
     maxX = Max(motionVector.X, maxX);
     maxY = Max(motionVector.Z, maxZ);
     maxZ = Max(motionVector.Z, maxZ);
     minX = Min(motionVector.X, minX);
     minY = Min(motionVector.Z, minY);
     minZ = Min(motionVector.Z, minZ);
     Console.WriteLine("Max: {0}, {1}, {2}", maxX, maxY, maxZ);
     Console.WriteLine("Min: {0}, {1}, {2}", minX, minY, minZ);
 }
Exemplo n.º 14
0
        //=============================================
        //Reference C2: Externally sourced algorithms
        //Purpose: takes the accelerometer readings and checks to see if device was shaken
        //Date: 11/10/2018
        //Source: W3 school
        //Author: unknown
        //URL: https://www.w3.org/TR/accelerometer/
        //Adaption Required: Lowered the reading amounts (sensitivity) and changed the code to return a bool
        // depending on if the device was shaken or not.
        //=============================================

        // Check to see if the device was shaken
        private Boolean WasTheDeviceShaken(MotionVector value)
        {
            if (value.X > 15 || value.Y > 15 || value.Z > 15)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 15
0
        public Trajectory Transform(Trajectory trj)
        {
            List <MotionVector> mvs = new List <MotionVector>();

            for (int i = 0; i < trj.Count; ++i)
            {
                MotionVector mv = trj[i];
                mv.point = Transform(trj[i].point);
                mvs.Add(mv);
            }
            return(new Trajectory(mvs));
        }
Exemplo n.º 16
0
        private double getDev(MotionVector start, MotionVector end, MotionVector middle)
        {
            Debug.Assert(end.t > start.t && middle.t > start.t && middle.t < end.t);
            GeoPoint pStart = start.point, pEnd = end.point;
            double   lat, lng;

            lat = (pEnd.Lat - pStart.Lat) / (end.t - start.t) * (middle.t - start.t);
            lng = (pEnd.Lng - pStart.Lng) / (end.t - start.t) * (middle.t - start.t);
            double dev = GeoPoint.GetDistance(new GeoPoint(lat, lng), middle.point);

            return(dev);
        }
Exemplo n.º 17
0
    public IEnumerator flowMesh(List <GameObject> triangles)
    {
        GetComponent <MeshRenderer> ().enabled = false;

        //yield return new WaitForSeconds (2f);

        MotionVector[] instructions = new MotionVector[triangles.Count];
        for (int n = 0; n < triangles.Count; n++)
        {
            //instructions [n].translation = new Vector3 (Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized;
            instructions [n].rotation    = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized;
            instructions [n].translation = instructions [n].rotation * scale;
        }
        Vector3 rot = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized;

        for (int i = 0; i < 90; i++)
        {
            transform.Rotate(rot * 4);


            int c = 0;
            foreach (GameObject tri in triangles)
            {
                tri.transform.Rotate(instructions [c].rotation * 4);
                if (i < 45)
                {
                    tri.transform.Translate(instructions[c].translation);
                }
                else
                {
                    tri.transform.Translate(instructions[c].translation * -1f);
                }

                c++;
            }
            yield return(null);
        }

        GetComponent <MeshRenderer> ().enabled = true;
        if (GetComponent <Collider> ())
        {
            GetComponent <Collider> ().enabled = true;
        }
        foreach (GameObject tri in triangles)
        {
            Destroy(tri);
        }
        transform.rotation = initial;
        yield return(new WaitForSeconds(.05f));

        transform.rotation = initial;
    }
Exemplo n.º 18
0
 /// <summary>
 /// Create fluid simulation.
 /// </summary>
 /// <param name="renderer">Renderer to use for drawing.</param>
 /// <param name="resolution">Resolution of renderering, from 0.0 to 1.0. The higher the resolution, the nice the simulation looks.</param>
 /// <param name="viscosity">Viscosity of the fluid.</param>
 /// <param name="diffusionRate">Diffusion rate of the fluid.</param>
 /// <param name="deltaTime">How fast to run simulation (milliseconds between simulation steps).</param>
 public FluidSimulation(IFluidRenderer renderer, float resolution, float viscosityConstant, float diffusionRateConstant, float gravityConstant, float terminalVelocityConstant, float deltaTime)
 {
     this.renderer              = renderer;
     this.resolution            = resolution;
     VISCOSITY_CONSTANT         = viscosityConstant;
     DIFFUSION_RATE_CONSTANT    = diffusionRateConstant;
     GRAVITY_CONSTANT           = gravityConstant;
     TERMINAL_VELOCITY_CONSTANT = terminalVelocityConstant;
     dt             = deltaTime;
     deviceMotion   = new MotionVector();
     deviceMotion.X = 0.0d; deviceMotion.Y = 1.0d; deviceMotion.Z = 9.8d;
     SetupSimulation();
 }
Exemplo n.º 19
0
        private void MarkVector(MotionVector motionVector)
        {
            // If there was not confused vector from this point we don't start another
            if (_rooms[motionVector.End.Uid].LastVectorEnter?.EqualsWithStartTime(motionVector) ?? false)
            {
                return;
            }

            _logger.Info(motionVector.ToString());

            _rooms[motionVector.Start.Uid].MarkLeave(motionVector);
            _rooms[motionVector.End.Uid].MarkEnter(motionVector);
        }
Exemplo n.º 20
0
        public void MarkLeave(MotionVector vector)
        {
            DecrementNumberOfPersons();

            if (AreaDescriptor.MaxPersonCapacity == 1)
            {
                SetProbability(Probability.Zero);
            }
            else
            {
                //TODO change this value
                SetProbability(Probability.FromValue(0.1));
            }
        }
Exemplo n.º 21
0
        private async Task MarkVector(MotionVector motionVector)
        {
            // If there was not confused vector from this point we don't start another
            if (_rooms[motionVector.End.Uid].LastVectorEnter?.EqualsWithStartTime(motionVector) ?? false)
            {
                return;
            }

            Logger.LogInformation(motionVector.ToString());

            await _rooms[motionVector.Start.Uid].MarkLeave(motionVector).ConfigureAwait(false);

            _rooms[motionVector.End.Uid].MarkEnter(motionVector);
        }
        /// <summary>
        /// Marks enter to target room and leave from source room
        /// </summary>
        /// <param name="motionVector"></param>
        /// <returns></returns>
        private async Task MarkVector(MotionVector motionVector)
        {
            var targetRoom = _roomService.GetTargetRoom(motionVector);
            var sourceRoom = _roomService.GetSourceRoom(motionVector);

            // If there was no confused vector from this point we don't start another
            //if (targetRoom.HasSameLastTimeVector(motionVector)) return;

            Logger.LogInformation(motionVector.ToString());

            await sourceRoom.MarkLeave(motionVector);

            targetRoom.MarkEnter(motionVector);
        }
Exemplo n.º 23
0
        public async Task MarkLeave(MotionVector vector)
        {
            DecrementNumberOfPersons();

            if (_areaDescriptor.MaxPersonCapacity == 1)
            {
                await SetProbability(Probability.Zero).ConfigureAwait(false);
            }
            else
            {
                //TODO change this value
                await SetProbability(Probability.FromValue(0.1)).ConfigureAwait(false);
            }
        }
Exemplo n.º 24
0
        void LimitsTestAction(MotionVector a)
        {
            var xVal = a.X;
            var yVal = a.Y;
            var zVal = a.Z;

            //Max
            if (xVal > maxX)
            {
                maxX = xVal;
                Console.WriteLine("X max: " + maxX);
            }

            if (yVal > maxY)
            {
                maxY = yVal;
                Console.WriteLine("Y max: " + maxY);
            }

            if (zVal > maxZ)
            {
                maxZ = zVal;
                Console.WriteLine("Z max: " + maxZ);
            }



            //Min


            if (xVal > minX)
            {
                minX = xVal;
                Console.WriteLine("X min: " + minX);
            }

            if (yVal < minY)
            {
                minY = yVal;
                Console.WriteLine("Y min: " + minY);
            }

            if (zVal < minZ)
            {
                minZ = zVal;
                Console.WriteLine("Z min: " + minZ);
            }
        }
Exemplo n.º 25
0
        public void Stop(Axis axis, bool setTarget = false)
        {
            MotionVector.GetAxis(axis).Current = 0;

            if (axis == Axis.X)
            {
                ObjectToMove.Position.SetLeft(FrameStartPosition.Left);
            }
            else if (axis == Axis.Y)
            {
                ObjectToMove.Position.SetTop(FrameStartPosition.Top);
            }

            if (setTarget)
            {
                MotionVector.GetAxis(axis).SetTarget(0, 0);
            }
        }
Exemplo n.º 26
0
        private void HandleVector(MotionVector motionVector)
        {
            var confusionPoints = _rooms[motionVector.End.Uid].GetConfusingPoints(motionVector);

            if (confusionPoints.Count == 0)
            {
                MarkVector(motionVector);
            }
            else if (_rooms[motionVector.Start.Uid].NumberOfPersonsInArea > 0)
            {
                _logger.Info($"{motionVector} [Confused: {string.Join(" | ", confusionPoints)}]");
                _confusedVectors.Add(motionVector.Confuze(confusionPoints));
            }
            // If there is no more people in area this confusion is resolved immediately because it is physically impossible
            else
            {
                _logger.Info($"{motionVector} [Deleted]");
            }
        }
        /// <summary>
        /// Handle move between rooms represented by <seealso cref="MotionVector"/>
        /// </summary>
        /// <param name="motionVector"></param>
        private async Task HandleVector(MotionVector motionVector)
        {
            var confusionPoints = _roomService.GetConfusingPoints(motionVector);

            if (confusionPoints.Count == 0)
            {
                await MarkVector(motionVector);
            }
            else if (_roomService.GetSourceRoom(motionVector).NumberOfPersonsInArea > 0)
            {
                Logger.LogInformation($"{motionVector} [Confused: {string.Join(" | ", confusionPoints)}]");
                _confusedVectors.Add(motionVector.WithConfuze(confusionPoints));
            }
            // If there is no more people in area this confusion is resolved immediately because it is physically impossible
            else
            {
                Logger.LogInformation($"{motionVector} [Deleted]");
            }
        }
Exemplo n.º 28
0
        public static MotionVector FixAccelerometerRelative(MotionVector deviceMotion)
        {
            MotionVector result = deviceMotion;

            if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.Android)
            {
                var     rotation  = CrossRotationService.Instance.GetRotation();
                int[][] axisSwaps = new int[4][]
                {
                    new int[4] {
                        1, -1, 0, 1
                    },                                  // ROTATION_0
                    new int[4] {
                        -1, -1, 1, 0
                    },                                   // ROTATION_90
                    new int[4] {
                        -1, 1, 0, 1
                    },                                  // ROTATION_180
                    new int[4] {
                        1, 1, 1, 0
                    }                                  // ROTATION_270
                };

                double[] motionVals = new double[3] {
                    deviceMotion.X, deviceMotion.Y, deviceMotion.Z
                };
                int[] axisSwap = axisSwaps[(int)rotation];
                result.X = (double)axisSwap[0] * motionVals[axisSwap[2]];
                result.Y = (double)axisSwap[1] * motionVals[axisSwap[3]] * -1; // Need to flip Y.
                result.Z = motionVals[2];
            }

            if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.iOS)
            {
                result.X *= -1;
                result.Y *= -1;
            }
            return(result);
        }
Exemplo n.º 29
0
        void LimitsTestFunction(MotionVector a)
        {
            var x = a.X;
            var y = a.Y;
            var z = a.Z;

            if (x > maxX)
            {
                maxX = x;
                Console.WriteLine("x Max: " + maxX);
            }
            if (y > maxY)
            {
                maxY = x;
                Console.WriteLine("x Max: " + maxX);
            }
            if (z > maxZ)
            {
                maxZ = x;
                Console.WriteLine("x Max: " + maxX);
            }

            if (x < minX)
            {
                minX = x;
                Console.WriteLine("x Min: " + minX);
            }
            if (y < minY)
            {
                minY = y;
                Console.WriteLine("y Min: " + minY);
            }
            if (z < minZ)
            {
                minZ = z;
                Console.WriteLine("z Min: " + minZ);
            }
        }
Exemplo n.º 30
0
        private void HandleVector(MotionVector motionVector)
        {
            var confusionPoints = _rooms[motionVector.End.Uid].GetConfusingPoints(motionVector);

            if (confusionPoints.Count == 0)
            {
                //TODO change this to Async?
                //https://github.com/dotnet/reactive/issues/459
                //https://stackoverflow.com/questions/23006852/howto-call-back-async-function-from-rx-subscribe
                //https://stackoverflow.com/questions/37412129/how-to-subscribe-with-async-method-in-rx
                MarkVector(motionVector).GetAwaiter().GetResult();
            }
            else if (_rooms[motionVector.Start.Uid].NumberOfPersonsInArea > 0)
            {
                Logger.LogInformation($"{motionVector} [Confused: {string.Join(" | ", confusionPoints)}]");
                _confusedVectors.Add(motionVector.Confuze(confusionPoints));
            }
            // If there is no more people in area this confusion is resolved immediately because it is physically impossible
            else
            {
                Logger.LogInformation($"{motionVector} [Deleted]");
            }
        }