点到折线最短距离所在点距离折线起点的累积距离

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using ESRI.ArcGIS.Geometry;
  6 using RGeos.Geometry
  7
  8 namespace RGeos.Geometry
  9 {
 10     public class CulmulateDistance
 11     {
 12         /// <summary>
 13         /// 点到折线最短距离处距离折线起点的累积距离
 14         /// </summary>
 15         /// <param name="P">任意一点</param>
 16         /// <param name="polyline">折线</param>
 17         /// <returns></returns>
 18         public static double CulmulateDist_Point_to_Polyline(IPoint P, IPolyline polyline)
 19         {
 20             ISegmentCollection segs = polyline as ISegmentCollection;
 21             double min = double.MaxValue;
 22             int segIndex = -1;//最短距离所在档的索引
 23             for (int i = 0; i < segs.SegmentCount; i++)
 24             {
 25                 //点到每条线段的最短距离
 26                 double dis = Dist_Point_to_Segment(P, segs.get_Segment(i));
 27                 if (dis < min)
 28                 {
 29                     min = dis;
 30                     segIndex = i;//取出最小的一个
 31                 }
 32             }
 33             double culmulateDis = 0;
 34             for (int i = 0; i < segs.SegmentCount; i++)
 35             {
 36                 if (segIndex != i)
 37                 {
 38                     culmulateDis += segs.get_Segment(i).Length;
 39                 }
 40                 else
 41                 {
 42                     ISegment current = segs.get_Segment(i);
 43                     Vector3d v = new Vector3d();
 44                     v.X = current.ToPoint.X - current.FromPoint.X;
 45                     v.Y = current.ToPoint.Y - current.FromPoint.Y;
 46
 47                     Vector3d w = new Vector3d();
 48                     w.X = P.X - current.FromPoint.X;
 49                     w.Y = P.Y - current.FromPoint.Y;
 50
 51                     double c1 = dot(w, v);//投影长度
 52                     if (c1 <= 0)//这种情况最短距离在该线段的起点处
 53                     {
 54                         break;
 55                     }
 56                     double c2 = dot(v, v);
 57                     if (c2 <= c1)//这种情况最短距离在该线段的终点处
 58                     {
 59                         culmulateDis += Math.Sqrt(c2);
 60                         break;
 61                     }
 62
 63                     double b = c1 / c2;
 64                     culmulateDis += Math.Sqrt(c1);
 65                     IPoint Pb = new PointClass();
 66                     Pb.X = current.FromPoint.X + b * v.X;
 67                     Pb.Y = current.FromPoint.Y + b * v.Y;
 68                     break;
 69                 }
 70             }
 71             return culmulateDis;
 72         }
 73
 74         public static IPoint GetCentrePoint(IPolygon polygon)
 75         {
 76             IArea pArea = polygon as IArea;
 77             IPoint pt = new PointClass();
 78             pt.X = pArea.Centroid.X;
 79             pt.Y = pArea.Centroid.Y;
 80             return pt;
 81         }
 82
 83         public static double Dist_Point_to_Segment(IPoint P, ISegment S)
 84         {
 85             Vector3d v = new Vector3d();
 86             v.X = S.ToPoint.X - S.FromPoint.X;
 87             v.Y = S.ToPoint.Y - S.FromPoint.Y;
 88
 89             Vector3d w = new Vector3d();
 90             w.X = P.X - S.FromPoint.X;
 91             w.Y = P.Y - S.FromPoint.Y;
 92
 93             double c1 = dot(w, v);
 94             if (c1 <= 0)
 95                 return d(P, S.FromPoint);
 96
 97             double c2 = dot(v, v);
 98             if (c2 <= c1)
 99                 return d(P, S.ToPoint);
100
101             double b = c1 / c2;
102             IPoint Pb = new PointClass();
103             Pb.X = S.FromPoint.X + b * v.X;
104             Pb.Y = S.FromPoint.Y + b * v.Y;
105             return d(P, Pb);
106         }
107         /// <summary>
108         /// 向量的模
109         /// </summary>
110         /// <param name="v"></param>
111         /// <returns></returns>
112         public static double norm(Vector3d v)
113         {
114             return Math.Sqrt(dot2(v, v));  // norm = length of vector
115         }
116         /// <summary>
117         /// 2D数量积,点乘
118         /// </summary>
119         /// <param name="u"></param>
120         /// <param name="v"></param>
121         /// <returns></returns>
122         public static double dot2(Vector3d u, Vector3d v)
123         {
124             return ((u).X * (v).X + (u).Y * (v).Y);
125         }
126         public static double dot(Vector3d u, Vector3d v)
127         {
128             return ((u).X * (v).X + (u).Y * (v).Y + (u).Z * (v).Z);
129         }
130
131         public static double d(IPoint P, IPoint P1)
132         {
133             return Math.Sqrt((P1.X - P.X) * (P1.X - P.X) + (P1.Y - P.Y) * (P1.Y - P.Y));
134         }
135
136         /// <param name="x">增量X</param>
137         /// <param name="y">增量Y</param>
138         /// <returns>象限角</returns>
139         public static double GetQuadrantAngle(double x, double y)
140         {
141             double theta = Math.Atan(y / x);
142             if (x > 0 && y == 0) return 0;
143             if (x == 0 && y > 0) return Math.PI / 2;
144             if (x < 0 && y == 0) return Math.PI;
145             if (x == 0 && y < 0) return 3 * Math.PI / 2;
146
147             if (x > 0 && y > 0) return theta;
148             if (x > 0 && y < 0) return Math.PI * 2 + theta;
149             if (x < 0 && y > 0) return theta + Math.PI;
150             if (x < 0 && y < 0) return theta + Math.PI;
151             return theta;
152         }
153     }
154 }
时间: 2025-01-15 14:06:03

点到折线最短距离所在点距离折线起点的累积距离的相关文章

【转】通过经纬度坐标计算距离的方法(经纬度距离计算)

最近在网上搜索“通过经纬度坐标计算距离的方法”,发现网上大部分都是如下的代码: #define PI 3.14159265 static double Rc = 6378137;  // 赤道半径 static double Rj = 6356725;  // 极半径 class JWD { public: double m_Longitude, m_Latitude; double m_RadLo, m_RadLa; double Ec; double Ed; public: JWD(doub

js获取页面元素距离浏览器工作区顶端的距离

先介绍几个属性:(暂时只测了IE和firefox,实际上我工作中用到的最多的是chrome) 网页被卷起来的高度/宽度(即浏览器滚动条滚动后隐藏的页面内容高度) (javascript)        document.documentElement.scrollTop //firefox (javascript)        document.documentElement.scrollLeft //firefox (javascript)        document.body.scro

获取页面元素距离浏览器工作区顶端的距离

先介绍几个属性:(暂时只测了IE和firefox,实际上我工作中用到的最多的是chrome) 网页被卷起来的高度/宽度(即浏览器滚动条滚动后隐藏的页面内容高度) (javascript)        document.documentElement.scrollTop //firefox (javascript)        document.documentElement.scrollLeft //firefox (javascript)        document.body.scro

Atitti knn实现的具体四个距离算法 欧氏距离、余弦距离、汉明距离、曼哈顿距离

Atitti knn实现的具体四个距离算法  欧氏距离.余弦距离.汉明距离.曼哈顿距离 1. Knn算法实质就是相似度的关系1 1.1. 文本相似度计算在信息检索.数据挖掘.机器翻译.文档复制检测等领域有着广泛的应用1 2. 汉明距离1 2.1. 历史及应用1 3. 曼哈顿距离2 3.1. SimHash + 汉明距离3 3.2. .简单共有词4 1. Knn算法实质就是相似度的关系 1.1. 文本相似度计算在信息检索.数据挖掘.机器翻译.文档复制检测等领域有着广泛的应用 数据挖掘的过程中,只用

各种距离 欧式距离、曼哈顿距离、切比雪夫距离、闵可夫斯基距离、标准欧氏距离、马氏距离、余弦距离、汉明距离、杰拉德距离、相关距离、信息熵

1. 欧氏距离(Euclidean Distance) 欧氏距离是最容易直观理解的距离度量方法,我们小学.初中和高中接触到的两个点在空间中的距离一般都是指欧氏距离. 二维平面上点a(x1,y1)与b(x2,y2)间的欧氏距离: 三维空间点a(x1,y1,z1)与b(x2,y2,z2)间的欧氏距离: n维空间点a(x11,x12,…,x1n)与b(x21,x22,…,x2n)间的欧氏距离(两个n维向量): Matlab计算欧氏距离: Matlab计算距离使用pdist函数.若X是一个m×n的矩阵,

echarts更改折线图区域颜色、折线颜色、折点颜色

series: [ { name: '订单流入总数', type: 'line', stack: '总量', areaStyle: { normal: { color: '#8cd5c2' //改变区域颜色 } }, itemStyle: { normal: { color: '#8cd5c2', //改变折线点的颜色 lineStyle: { color: '#8cd5c2' //改变折线颜色 } } }, data: [120, 132, 101, 134, 90, 230, 210] }

JAVA实现求一点到另两点连线的距离,计算两点之间的距离

直接上代码 /** *计算两点之间距离 */ public static double getDistance(Point start,Point end){ double lat1=start.getX().doubleValue(); double lat2=end.getX().doubleValue(); double lon1=start.getY().doubleValue(); double lon2=end.getY().doubleValue(); return Math.sq

计算线上距离线起点一定距离的点

#!/usr/bin/env python # -*- coding: utf-8 -*- from shapely.geometry import asShape import json import os from pyproj import Proj, transform # define the pyproj CRS # our output CRS wgs84 = Proj("+init=EPSG:4326") # output CRS pseudo_mercator = P

mongo 查询 距离 某个点 多少 米距离 感谢 提供的数据。 感谢 mvc的 demo 。反正 就是各种感谢 文档之类的。

昨天 去面试来着, 问了一下mong . 我记得mong支持 地理位置索引的,说了一下. 然后 面试官说 查询某个点 的 多少米范围, 这个该怎么实现? 我懵逼了.... 回去 查询了一下. 发现有 测试数据(度量有啊) //BsonElement bsonele = new BsonElement("address","南京 中华门"); /* * 创建测试数据: db.mapinfo.insert({"address" : "南京