4

dotnet C# 根据椭圆长度和宽度和旋转角计算出椭圆中心点的方法

 2 years ago
source link: https://lindexi.gitee.io/post/dotnet-C-%E6%A0%B9%E6%8D%AE%E6%A4%AD%E5%9C%86%E9%95%BF%E5%BA%A6%E5%92%8C%E5%AE%BD%E5%BA%A6%E5%92%8C%E6%97%8B%E8%BD%AC%E8%A7%92%E8%AE%A1%E7%AE%97%E5%87%BA%E6%A4%AD%E5%9C%86%E4%B8%AD%E5%BF%83%E7%82%B9%E7%9A%84%E6%96%B9%E6%B3%95.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
dotnet C# 根据椭圆长度和宽度和旋转角计算出椭圆中心点的方法

本文来告诉大家如何根据椭圆长度和宽度和旋转角计算出椭圆中心点的方法

方法很简单,请看代码

    /// <summary>
    /// 辅助进行椭圆点计算的类
    /// </summary>
    /// 我觉得这个类应该是框架有带,或现成的方法,但是一时间没找到
    static class EllipseCoordinateHelper
    {
        /// <summary>
        /// 计算椭圆中点坐标
        /// </summary>
        /// <param name="widthRadius"></param>
        /// <param name="heightRadius"></param>
        /// <param name="rotationAngle"></param>
        /// <returns></returns>
        public static (Pixel x, Pixel y) GetEllipseCoordinate(Pixel widthRadius, Pixel heightRadius,
            Degree rotationAngle)
        {
            // 以下为椭圆两个点的计算方法
            // 算法请看 https://astronomy.swin.edu.au/cms/astro/cosmos/E/Ellipse

            var absRotate = Math.Abs(rotationAngle.DoubleValue);
            var rad = Math.Abs(absRotate - 90);
            rad = rad * Math.PI / 180;
            var tan = Math.Tan(rad);

            var a = widthRadius.Value;
            var b = heightRadius.Value;
            var x = Math.Sqrt(1.0 / (1.0 / (a * a) + (tan * tan) / (b * b)));
            var y = x * tan;

            if (rotationAngle.DoubleValue < 0)
            {
                x = -x;
            }

            if (rotationAngle.DoubleValue > -90 && rotationAngle.DoubleValue < 90)
            {
                y = -y;
            }

            x = a + x;
            y = b + y;

            return (new Pixel(x), new Pixel(y));
        }
    }

我觉得以上是 WPF 框架有带的,但是一时半会没有找到在哪定义的,因此就自己写了一份

以上的 Pixel 和 Degree 的定义代码在 GitHub 上开源,请看 Office Open XML 的测量单位


本文会经常更新,请阅读原文: https://blog.lindexi.com/post/dotnet-C-%E6%A0%B9%E6%8D%AE%E6%A4%AD%E5%9C%86%E9%95%BF%E5%BA%A6%E5%92%8C%E5%AE%BD%E5%BA%A6%E5%92%8C%E6%97%8B%E8%BD%AC%E8%A7%92%E8%AE%A1%E7%AE%97%E5%87%BA%E6%A4%AD%E5%9C%86%E4%B8%AD%E5%BF%83%E7%82%B9%E7%9A%84%E6%96%B9%E6%B3%95.html ,以避免陈旧错误知识的误导,同时有更好的阅读体验。

如果你想持续阅读我的最新博客,请点击 RSS 订阅,推荐使用RSS Stalker订阅博客,或者前往 CSDN 关注我的主页

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接: https://blog.lindexi.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系

无盈利,不卖课,做纯粹的技术博客

以下是广告时间

推荐关注 Edi.Wang 的公众号
lindexi%2F201985113622445

欢迎进入 Eleven 老师组建的 .NET 社区
lindexi%2F20209121930471745.jpg

以上广告全是友情推广,无盈利


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK