美文网首页狮猿社_Rhino
RhinoCommon:在球体上生成等距点

RhinoCommon:在球体上生成等距点

作者: 锦囊喵 | 来源:发表于2020-09-05 10:32 被阅读0次

    https://bduvenhage.me/geometry/2019/07/31/generating-equidistant-vectors.html

    image.png

    话不多说,代码如下:

    using System;
    using Rhino;
    using Rhino.Commands;
    using Rhino.Geometry;
    
    namespace SectionGridTool.Commands
    {
        [System.Runtime.InteropServices.Guid("c7c0da31-3e16-49bc-8b09-0f2c53998adf")]
        public class geoSphere : Command
        {
            static geoSphere _instance;
            public geoSphere()
            {
                _instance = this;
            }
    
            ///<summary>The only instance of the geoSphere command.</summary>
            public static geoSphere Instance
            {
                get { return _instance; }
            }
    
            public override string EnglishName
            {
                get { return "geoSphere"; }
            }
    
            protected override Result RunCommand(RhinoDoc doc, RunMode mode)
            {
                // TODO: complete command.
                createPoints(doc);
                return Result.Success;
            }
    
            private void createPoints(RhinoDoc doc)
            {
                double gr = (Math.Sqrt(5.0) + 1.0) / 2.0;  // golden ratio = 1.6180339887498948482
                double ga = (2.0 - gr) * (2.0 * Math.PI);  // golden angle = 2.39996322972865332
                int num_points = 1000;
                for (double i=1; i <= num_points; ++i) 
                {
                    double lat = Math.Asin(-1.0 + 2.0 * i / (num_points+1));
                    double lon = ga * i;
    
                    double x = 10 * Math.Cos(lon) * Math.Cos(lat);
                    double y = 10 * Math.Sin(lon) * Math.Cos(lat);
                    double z = 10 * Math.Sin(lat);
    
                    doc.Objects.AddPoint(new Point3d(x, y, z));
                }        
            }
        }
    }
    

    相关文章

      网友评论

        本文标题:RhinoCommon:在球体上生成等距点

        本文链接:https://www.haomeiwen.com/subject/qdotektx.html