Exemple #1
0
    public float[] GetAngles(DateTime datTim)
    {
        double alt;
        double azi;

        SunPosition.CalculateSunPosition(datTim, latitude, longitude, UTC, out azi, out alt);
        return(new float[2] {
            (float)alt, (float)azi
        });;
    }
Exemple #2
0
    void updatePosition(System.DateTime date)
    {
        IDictionary <string, double> result = SunPosition.CalculateSunPosition(date, 34, 118);
        float X = (float)(sunDistance * System.Math.Cos(result["azimuth"]));
        float Y = (float)(sunDistance * System.Math.Sin(result["azimuth"]));
        float Z = (float)(sunDistance * System.Math.Sin(result["altitude"]));

        transform.position          = new Vector3(X, Y, Z);
        lighting.transform.position = new Vector3(X, Y, Z);
    }
Exemple #3
0
    void updatePosition(System.DateTime date)
    {
        IDictionary <string, double> result = SunPosition.CalculateSunPosition(date, latitude, longitude);

        x = (float)(sunDistance * System.Math.Cos(result["azimuth"]) * System.Math.Cos(result["altitude"]));
        z = (float)(sunDistance * System.Math.Sin(result["azimuth"]) * System.Math.Cos(result["altitude"]));
        y = (float)(sunDistance * System.Math.Sin(result["altitude"]));
        transform.position          = new Vector3(x, y, z);
        lighting.transform.position = new Vector3(x, y, z);
    }
Exemple #4
0
    void SetPosition()
    {
        Vector3 angles = new Vector3();

        SunPosition.CalculateSunPosition(time, (double)latitude, (double)longitude, out azi, out alt);
        angles.x = (float)alt * Mathf.Rad2Deg;
        angles.y = (float)azi * Mathf.Rad2Deg;
        transform.localRotation = Quaternion.Euler(angles);
        light.intensity         = Mathf.InverseLerp(-12, 0, angles.x);
    }
Exemple #5
0
        public void AutomntTest()
        {
            double height;
            double azimuth;

            SunPosition.GetSunPosition(-50, 30, new DateTime(2014, 3, 1, 15, 15, 0), out height, out azimuth);

            Assert.AreEqual(height, 15.66, Delta);
            Assert.AreEqual(azimuth, 275.79, Delta);
        }
 public static Hex Direction(SunPosition sunPosition)
 {
     return(sunPosition switch {
         SunPosition.NorthWest => new Hex(0, +1, -1),
         SunPosition.NorthEast => new Hex(-1, +1, 0),
         SunPosition.East => new Hex(-1, 0, +1),
         SunPosition.SouthEast => new Hex(0, -1, +1),
         SunPosition.SouthWest => new Hex(+1, -1, 0),
         SunPosition.West => new Hex(+1, 0, -1),
         _ => throw new ArgumentOutOfRangeException(nameof(sunPosition), sunPosition, null)
     });
Exemple #7
0
    public void Hinode_shikatanai()//日の出ボタン押したときの制御
    {
        //無形文化遺産コピー
        csvload     d1 = scriptbox.GetComponent <csvload>();
        SunPosition d2 = scriptbox.GetComponent <SunPosition>();

        risetime      = d1.CSVsunrise((int)d2.X) - d1.CSVuse((int)d2.X); //日の出時刻(秒)を求める
        settime       = d1.CSVsunset((int)d2.X) - d1.CSVuse((int)d2.X);  //日の出時刻(秒)を求める
        risetime_time = d1.CSVsunrise((int)d2.X);
        settime_time  = d1.CSVsunset((int)d2.X);
        //時間を(日の出時刻) - (南中時刻のずれ) にずらす
    }
Exemple #8
0
    // Update is called once per frame
    void Update()
    {
        GameObject  sunpos = GameObject.Find("ScriptBox");
        SunPosition script = sunpos.GetComponent <SunPosition>();
        csvload     d1     = sunpos.GetComponent <csvload>();


        this.targetText = this.GetComponent <Text>();
        //this.targetText.text = "数値1="+script.xx +"数値2="+script.yy ;
        this.targetText.text = "通日=" + script.xx + "\n視赤緯=" + -script.theta + "\n現在地緯度=35\n経度=135\n南中高度=" + (-script.theta + 55)
                               + "\n日の出時刻=" + d1.CSVdebug((int)script.xx, 2) + "\n日没時刻=" + d1.CSVdebug((int)script.xx, 6)
                               + "\n南中時刻=" + d1.CSVdebug((int)script.xx, 4);
    }
Exemple #9
0
    // Update is called once per frame
    void Update()
    {
        lightComp.shadows = LightShadows.Hard;
        lightComp.type    = LightType.Directional;
        lightComp.color   = Color.blue;


        //Getting GPS coordinates of the device from Location Service
        latitude  = LocationService.Instance.latitude;
        longitude = LocationService.Instance.longitude;
        Debug.Log("Latitude: " + latitude + "Longitude: " + longitude);

        //Getting Azimuth and Alitutde angle according to Sun's current position using SunPosition Service
        //PSA algorithm can also be used from class SunPositionPSA
        //PSA algorithm was valid from 1999-2015 after that it introduces a error in calculatin SunPosition

        SunPosition sp = new SunPosition();

        sp.CalculateSunPosition(DateTime.Now, latitude, longitude);
        azimuthAngle  = sp.azimuth;
        altitudeAngle = sp.altitude;
        Debug.Log("Azimuth: " + azimuthAngle + " altitude: " + altitudeAngle);

        //Estimating the position of sun according to the users GPS coordinates(latitude,longitude)
        calculateSunDirection(azimuthAngle, altitudeAngle);

        //Hitting the web api to find out the current skycondition(Cloudy,Partly Cloudy,Clear sky)
        skyCondition = WeatherApi.Instance.skyCondition;
        skyCondition = "clear-day";
        float[] sensorValue = null;
        //Calculating shadow Strength according to SkyConditions
#if UNITY_ANDROID
        if (plugin != null)
        {
            //Initializing the plugin to read Ambient sensor light value in lux units
            sensorValue = plugin.Call <float[]>("getSensorValues", "light");
            if (sensorValue != null)
            {
                lightComp.shadowStrength = calculateShadowIntensity(sensorValue[0], skyCondition);
            }
            else
            {
                lightComp.shadowStrength = 0F;
            }
        }
    #endif

        message = "The shadow strength is: " + lightComp.shadowStrength + " ALS value is: " + sensorValue[0] +
                  " Latitude is: " + latitude + " Longitude is: " + longitude + " Sky Condition is: " + skyCondition +
                  " Azimuth is: " + azimuthAngle + " Altitude is: " + altitudeAngle;
    }
    private void ChangeSunPosition()
    {
        var    angles = new Vector3();
        double alt;
        double azi;

        SunPosition.CalculateSunPosition(dateTimeNow, (double)latitude, (double)longitude, out azi, out alt);
        angles.x = (float)alt * Mathf.Rad2Deg;
        angles.y = (float)azi * Mathf.Rad2Deg;

        EnviromentSettings.SetSunAngle(angles);

        UpdateWheelAccordingToSun();
        UpdateNumericInputs();
    }
Exemple #11
0
    /*
     * Called at each frame
     * Rotate the sun given the speed
     */
    void Update()
    {
        dateTime = dateTime.AddHours(speed * Time.deltaTime);
        Vector3 angles = new Vector3();
        double  alt;
        double  azi;

        SunPosition.CalculateSunPosition(dateTime, latitude, longitude, UTC, out azi, out alt);

        angles.x = (float)alt * Mathf.Rad2Deg;
        angles.y = (float)azi * Mathf.Rad2Deg;

        transform.eulerAngles = angles;
        sunLight.intensity    = Mathf.InverseLerp(-12, 0, angles.x);
    }
Exemple #12
0
    private void X_SetSunAngle()
    {
        double  alt, azi;
        Vector3 angles = new Vector3();

        // Berechnen
        SunPosition.CalculateSunPosition(_time, (double)_latitude, (double)_longitude, out azi, out alt);
        // Als Euler Winkel speichern
        angles.x = (float)alt * Mathf.Rad2Deg;
        angles.y = (float)azi * Mathf.Rad2Deg;
        _sunLight.transform.rotation = Quaternion.Euler(angles);
        // Sonne und Nachtlicht (de)aktivieren
        _sunLight.intensity = Mathf.InverseLerp(-12, 0, angles.x);
        _sunLight.gameObject.SetActive(_sunLight.intensity > 0);
        _nightLight.gameObject.SetActive(_sunLight.intensity == 0);
    }
Exemple #13
0
    public void Hinode()//日の出ボタン押したときの制御
    {
        //無形文化遺産コピー
        //   Debug.Log("おはよう");

        csvload     d1 = scriptbox.GetComponent <csvload>();
        SunPosition d2 = scriptbox.GetComponent <SunPosition>();

        risetime_time = d1.CSVsunrise((int)d2.X);
        settime_time  = d1.CSVsunset((int)d2.X);
        risetime      = d1.CSVsunrise((int)d2.X) - d1.CSVuse((int)d2.X); //日の出時刻(秒)を求める
        settime       = d1.CSVsunset((int)d2.X) - d1.CSVuse((int)d2.X);  //日の出時刻(秒)を求める
        //時間を(日の出時刻) - (南中時刻のずれ) にずらす

        Sunwarp((risetime / 86400));  //1日=86400秒 アニメーションを飛ばす

        Sunrisetime(risetime / 3600); //1時間=3600秒 timekeeperに干渉
    }
Exemple #14
0
    // Update is called once per frame
    void Update()
    {
        date = new System.DateTime(2020, 4, 8, (int)hour, (int)minutes, 0);
        updatePosition(date);
        Debug.Log(date.ToString());
        IDictionary <string, double> result = SunPosition.CalculateSunPosition(date, 34, 118);

        minutes += 0.5f;
        if (minutes >= 60)
        {
            minutes = 0;
            hour   += 1;
        }
        if (hour >= 23)
        {
            hour = 0;
        }
    }
Exemple #15
0
        public static Board CastShadow(Board board, Hex origin, SunPosition sunPosition)
        {
            int tileCode = board.Get(origin);
            int height   = Tile.GetPieceHeight(tileCode);

            for (int i = 1; i <= height; i++)
            {
                Hex h = (origin + i * Shadow.Shadow.Direction(sunPosition));
                if (board.TryGetValue(h, out int t))
                {
                    board[h] = Tile.GetShadowHeight(t) < height
                        ? Tile.SetShadowHeight(t, height)
                        : t;
                }
            }

            return(board);
        }
    IEnumerator AdjustLightAngle()
    {
        while (true)
        {
            // Refresh latitude/longitude
            lat = Input.location.lastData.latitude;
            lon = Input.location.lastData.longitude;

            // Refresh Sun position
            SunPosition.Position sunPos = SunPosition.CalculateSunPosition(DateTime.Now, lat, lon);
            sunAltitude = sunPos.Altitude;
            sunAzimuth  = sunPos.Azimuth;

            double xRot = sunAltitude;
            // Adjust to account for initial orientation of phone
            double yRot = sunAzimuth - initialNorthOffset + 180;

            // Adjust rotation angle of directional light (i.e. sun)
            transform.rotation = Quaternion.Euler((float)xRot, (float)yRot, 0.0f);

            yield return(new WaitForSeconds(shadowRefreshSeconds));
        }
    }
 public void AutumnalEquinoxTest()
 {
     Assert.AreEqual(SunPosition.GetSunDeclination(new DateTime(2014, 9, 22, 2, 29, 0)), 0, Delta);
 }
 public void VernalEquinoxTest()
 {
     Assert.AreEqual(SunPosition.GetSunDeclination(new DateTime(2012, 3, 21)), 0, Delta);
 }
Exemple #19
0
        /// <summary>
        /// EclipsedSatFilter核心
        /// </summary>
        /// <param name="gData"></param>
        /// <returns></returns>
        public override bool Revise(ref EpochInformation gData)
        {
            //   Time epoch = gData.CorrectedTime;
            Time epoch = gData.ReceiverTime;



            List <SatelliteNumber> satRejectedSet = new List <SatelliteNumber>();
            // Set the threshold to declare that satellites are in eclipse
            // threshold = cos(180 - coneAngle/2)
            double threshold = Math.Cos((CoordConsts.PI - ConeAngle / 2.0 * CoordConsts.DegToRadMultiplier));

            // Compute Sun position at this epoch, and store it in a Triple
            SunPosition sunPosition = new SunPosition();
            // Variables to hold Sun and Moon positions
            XYZ sunPos = (sunPosition.GetPosition(epoch));

            // Loop through all the satellites
            foreach (var sat in gData.EnabledSats)
            {
                SatelliteNumber prn = sat.Prn;
                //Define a XYZ that will hold satellite position, in ECEF
                XYZ svPos = gData[prn].Ephemeris.XYZ; //.GetSatPostion(satelliteType);
                XYZ rk    = svPos.UnitVector();       // Unitary vector from Earth mass center to satellite

                // Unitary vector from Earth mass center to Sun
                XYZ ri = sunPos.UnitVector();

                //Get dot product between unitary vectors = cosine(angle)
                double cosAngle = ri.Dot(rk);

                // Check if satellite is within shadow
                if (cosAngle <= threshold)
                {
                    // If satellite is eclipsed, then schedule it for removal
                    satRejectedSet.Add(prn);

                    if (!ShadowEpoch.ContainsKey(prn))
                    {
                        ShadowEpoch.Add(prn, epoch);
                    }
                    // Keep track of last known epoch the satellite was in eclipse
                    ShadowEpoch[prn] = epoch;

                    continue;
                }
                else
                {
                    // Maybe the satellite is out fo shadow, but it was recently
                    // in eclipse. Check also that.
                    if (ShadowEpoch.ContainsKey(prn))
                    {
                        // // If satellite was recently in eclipse, check if elapsed
                        // time is less or equal than postShadowPeriod
                        double temp = (double)Math.Abs(epoch - ShadowEpoch[prn]);

                        if (temp <= PostShadowPeriod)
                        {
                            // Satellite left shadow, but too recently. Delete it
                            satRejectedSet.Add(prn);
                        }
                        else
                        {
                            // If satellite left shadow a long time ago, set it free
                            ShadowEpoch.Remove(prn);
                        }
                    }
                }
            }
            //debug
            if (satRejectedSet.Count > 0 && satRejectedSet.FindAll(m => !RemovedPrn.Contains(m)).Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(gData.Name + "," + gData.ReceiverTime + ",删除太阳阴影影响的卫星:");
                sb.Append(String.Format(new EnumerableFormatProvider(), "{0}", satRejectedSet));
                log.Debug(sb.ToString());
                RemovedPrn.AddRange(satRejectedSet.FindAll(m => !RemovedPrn.Contains(m)));
            }

            //Remove satellites with missing satData
            gData.Remove(satRejectedSet, true, "删除太阳阴影影响的卫星");


            return(true);
        }
 public void MidwinterTest()
 {
     Assert.AreEqual(SunPosition.GetSunDeclination(new DateTime(2013, 12, 22)), -23.0 - 27.0 / 60, Delta);
 }
Exemple #21
0
        protected override async void Start()
        {
            base.Start();

            hud = new MonoDebugHud(this);
            hud.Show(Color.Yellow, 24);

            var timeLabel = new Text {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Top
            };

            timeLabel.SetColor(new Color(0f, 1f, 0f));
            timeLabel.SetFont(font: CoreAssets.Fonts.AnonymousPro, size: 30);
            UI.Root.AddChild(timeLabel);

            var azAltLabel = new Text {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Bottom
            };

            azAltLabel.SetColor(new Color(0f, 1f, 0f));
            azAltLabel.SetFont(font: CoreAssets.Fonts.AnonymousPro, size: 30);
            UI.Root.AddChild(azAltLabel);

            ResourceCache.AutoReloadResources = true;
            Viewport.SetClearColor(Color.Black);

            earthNode = RootNode.CreateChild();
            earthNode.SetScale(5f);
            earthNode.Rotation = new Quaternion(0, -180, 0);
            var earthModel = earthNode.CreateComponent <Sphere>();

            earthModel.Material = Material.FromImage("Textures/Earth.jpg");

            Zone.AmbientColor = new Color(0.2f, 0.2f, 0.2f);
            LightNode.ChangeParent(Scene);
            LightNode.Position = Vector3.Zero;
            Light.Range        = 10;
            Light.Brightness   = 1f;
            Light.LightType    = LightType.Directional;

            AddMarker(0, 0, "(0, 0)");
            AddMarker(53.9045f, 27.5615f, "Minsk");
            AddMarker(51.5074f, 0.1278f, "London");
            AddMarker(40.7128f, -74.0059f, "New-York");
            AddMarker(37.7749f, -122.4194f, "San Francisco");
            AddMarker(39.9042f, 116.4074f, "Beijing");
            AddMarker(-31.9505f, 115.8605f, "Perth");

            var sunNode      = RootNode.CreateChild();
            var sunModelNode = sunNode.CreateChild();

            sunModelNode.Position = new Vector3(0, 4, 0);
            sunModelNode.SetScale(1);

            var sun = sunModelNode.CreateComponent <Sphere>();

            sun.Color = new Color(15, 10, 5);

            // update the Sun's position based on time
            var   time = DateTime.Now;
            float alt, az;

            SunPosition.CalculateSunPosition(time, 0f, 0f, out az, out alt);
            sunNode.Rotation = new Quaternion(-az, 0, alt);
            LightNode.SetDirection(RootNode.WorldPosition - sunModelNode.WorldPosition);

            timeLabel.Value  = time.ToShortTimeString();
            azAltLabel.Value = $"Azimuth: {az:F1},  Altitude: {alt:F1}";
        }
 public void MidsummerTest()
 {
     Assert.AreEqual(SunPosition.GetSunDeclination(new DateTime(2014, 6, 22)), 23.0 + 27.0 / 60, Delta);
 }