• 大小: 23KB
    文件类型: .cs
    金币: 1
    下载: 0 次
    发布日期: 2021-06-08
  • 语言: C#
  • 标签: 日照计算  

资源简介

该算法能够根据地球上任意位置计算其日出、日落时间,能够计算该地在指定时间的太阳高度角、方位角,能够计算日地距离、太阳位置等。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Common
{
    public class CalcCommon
    {
        public static string rootPath = Application.StartupPath;
        public static string GetWeather
        {
            get
            {
                return Path.Combine(rootPath “Plugins\\Weather\\Weather.txt“);
            }
        }

        #region 光照计算
        public static void CalcSunLight(DateTime now double lon double lat out double Hs out double As)
        {
            SunTimes.Instance.CalculateSunHsAs(now lon lat out Hs out As);
        }
        #endregion
    }

    /// 
    /// 计算日出日落时间
    /// 例如:CalculateSunRiseSetTimes((double)28.2172898 (double)113.0589294
    ///                System.DateTime.Now.AddDays(31) ref  sunrise ref sunrest ref yesrise ref yesset);
    /// 

    public class SunTimes
    {
        #region 变量

        private object mLock = new object();

        private const double mDR = Math.PI / 180;
        private const double mK1 = 15 * mDR * 1.0027379;

        private int[] mRiseTimeArr = new int[2] { 0 0 };
        private int[] mSetTimeArr = new int[2] { 0 0 };
        private double mRizeAzimuth = 0.0;
        private double mSetAzimuth = 0.0;

        private double[] mSunPositionInSkyArr = new double[2] { 0.0 0.0 };
        private double[] mRightAscentionArr = new double[3] { 0.0 0.0 0.0 };
        private double[] mDecensionArr = new double[3] { 0.0 0.0 0.0 };
        private double[] mVHzArr = new double[3] { 0.0 0.0 0.0 };

        private bool mIsSunrise = false;
        private bool mIsSunset = false;

        #endregion

        #region 单例模型

        private static readonly SunTimes mInstance = new SunTimes();    // The singleton instance

        private SunTimes() { }

        public static SunTimes Instance
        {
            get { return mInstance; }
        }

        #endregion

        #region 公有成员
        public static double Sin(double x)
        {
            return Math.Sin(x);
        }
        public static double Cos(double x)
        {
            return Math.Cos(x);
        }

        public static double Tan(double x)
        {
            return Math.Tan(x);
        }
        public static double PI
        {
            get { return Math.PI; }
        }
        /// 
        /// 计算日升日落时间,如果时间不合法,则返回false
        /// 

        /// Latitude coordinates.
        /// Longitude coordinates.
        /// Date for which to calculate.
        /// Sunrise time (output)
        /// Sunset time (output)
        /// Whether or not the sun rises at that day
        /// 

评论

共有 条评论

相关资源