当前位置: 首页>>代码示例>>C#>>正文


C# Point2D.DistanceTo方法代码示例

本文整理汇总了C#中Point2D.DistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C# Point2D.DistanceTo方法的具体用法?C# Point2D.DistanceTo怎么用?C# Point2D.DistanceTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Point2D的用法示例。


在下文中一共展示了Point2D.DistanceTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WorkerOnDoWork

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="doWorkEventArgs"></param>
        private void WorkerOnDoWork(object sender, DoWorkEventArgs doWorkEventArgs)
        {
            string outputPath = Path.GetDirectoryName(this.InputFile);
            string outputName = Path.GetFileNameWithoutExtension(this.InputFile) + "_filtered_clusters.xyz";
            string outputFile = Path.Combine(outputPath, outputName);

            var filtered = this.clusters.Where(x => x.Count >= this.MinCount).ToList();
            List<TrunkData> trunks = new List<TrunkData>();

               /* var output = new List<string>();
            foreach (var cluster in filtered)
            {
               output.AddRange(cluster.GetTextEnumerable());
            }
            File.WriteAllLines(outputFile, output);*/

            // Fit the circles
            List<string> csvOutput = new List<string>();
            csvOutput.Add("'type';'name';'coord-x';'coord-y';'coord-z';'coord-x2';'coord-y2';'coord-z2';'normal-x';'normal-y';'normal-z';'trimming-x';'trimming-y';'trimming-z';'dir-x';'dir-y';'dir-z';'length';'width';'radius';'radius2';'angle';'orientation';'edge-radius';'num-points';'tol-x-lower';'tol-x-upper';'tol-y-lower';'tol-y-upper';'tol-z-lower';'tol-z-upper';'tol-all-lower';'tol-all-upper';'tol-normal-lower';'tol-normal-upper';'tol-trimming-lower';'tol-trimming-upper';'tol-inplane-lower';'tol-inplane-upper';'tol-length-lower';'tol-length-upper';'tol-width-lower';'tol-width-upper';'tol-diameter-lower';'tol-diameter-upper';'tol-angle-lower';'tol-angle-upper'".Replace('\'', '"'));
            int count = 0;
            foreach (var cluster in filtered)
            {
                var fit = new CircleFitter2D(cluster.Points);

                if (fit.CircleRadius < this.MinRadius/100.0)
                    continue;
                if (fit.CircleRadius > this.MaxRadius/100.0)
                    continue;

                count++;
                trunks.Add(new TrunkData {Center = fit.CircleCenter, Radius = fit.CircleRadius, Points = cluster.Points, IdNumber = count});

                double scale = 1000;//39.37069644322352;
                string csvLine =
                    string.Format(
                        "'circle';'Circle {0}';{1};{2};{3};'';'';'';0.00;0.00;1.00;'';'';'';'';'';'';'';'';{4};'';'';'';'';'';'';'';'';'';'';'';'';'';'';'';'';'';'';'';'';'';'';'';'';'';'';''",
                        count, fit.CircleCenter.X * scale, fit.CircleCenter.Y * scale, fit.CircleCenter.Z * scale, fit.CircleRadius * scale);
                csvOutput.Add(csvLine.Replace('\'', '"'));
            }

            File.WriteAllLines(outputFile + ".csv", csvOutput);

            string display = string.Format("{0} filtered trunks, no points to process", trunks.Count);
            WorkerOnProgressChanged(sender, new ProgressChangedEventArgs(0, display));

            // Start writing results
            string resultPath = Path.Combine(outputPath, "results");
            if (!Directory.Exists(resultPath))
                Directory.CreateDirectory(resultPath);
            File.WriteAllText(Path.Combine(resultPath, "trunks.json"), JsonConvert.SerializeObject(trunks, Formatting.Indented));

            // If the point source file exists, start sorting through that
            if (!File.Exists(this.PointFile))
                return;

            long fileSize = new FileInfo(this.PointFile).Length;
            long readSize = 0;
            Regex extractor = new Regex(@"-{0,1}\d*\.\d+");
            int pointCount = 0;
            int sorted = 0;
            Dictionary<int, List<Point3D>> sortedPoints = new Dictionary<int, List<Point3D>>();
            using (StreamReader reader = new StreamReader(this.PointFile))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    readSize += ASCIIEncoding.ASCII.GetByteCount(line);

                    var matches = extractor.Matches(line);
                    if (matches.Count != 3)
                    {
                        throw new ArgumentException("Error, wrong number of matches in line: " + line);
                    }

                    Point3D v = new Point3D(double.Parse(matches[0].ToString()), double.Parse(matches[1].ToString()), double.Parse(matches[2].ToString()));
                    Point2D p = new Point2D(v.X, v.Y);
                    foreach (var trunkData in trunks)
                    {
                        Point2D c = new Point2D(trunkData.Center.X, trunkData.Center.Y);
                        if (c.DistanceTo(p) < 0.75)
                        {
                            sorted++;
                            if (sortedPoints.ContainsKey(trunkData.IdNumber))
                                sortedPoints[trunkData.IdNumber].Add(v);
                            else
                            {
                                sortedPoints[trunkData.IdNumber] = new List<Point3D> {v};
                            }
                        }
                    }

                    if (pointCount++%50 == 0)
                    {
                        display = string.Format("{0} filtered trunks, {2} sorted points, {1:0.00}% processed", trunks.Count, (double)readSize/fileSize * 100, sorted);
                        WorkerOnProgressChanged(sender, new ProgressChangedEventArgs(0, display));
//.........这里部分代码省略.........
开发者ID:mattj23,项目名称:tree_point_tools,代码行数:101,代码来源:ClusterProcessingViewModel.cs


注:本文中的Point2D.DistanceTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。