AE中常用的图形操作函数

 

/// <summary>
/// 返回点到图形之间的垂直距离
/// </summary>
/// <param name="pPoint"></param>
/// <param name="pGeo"></param>
/// <returns></returns>
   
public static double getPointToGeoDis(IPoint pPoint, IGeometry pGeo)
{
IProximityOperator Pro = pPoint as IProximityOperator;
double dis = Pro.ReturnDistance(pGeo);
return dis;
}

/// <summary>
/// 求两点间距离
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <returns></returns>
   
private double getDisByTwoPoint(IPoint p1, IPoint p2)
{
double step1 = (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y);
double step2 = Math.Sqrt(step1);
return step2;
}

/// <summary>
/// 利用两点生成一条PolyLine
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <returns></returns>
   
private IPolyline CreatePolyLineByTwoPoint(IPoint p1, IPoint p2)
{
INewLineFeedback m_LineFeed = new NewLineFeedback();
m_LineFeed.Start(p1);
m_LineFeed.AddPoint(p2);
IPolyline m_PolyLine = m_LineFeed.Stop();
return m_PolyLine;
}

/// <summary>
/// 粗略判断一个已知点是否在线上
/// </summary>
/// <param name="pPoint">已知点</param>
/// <param name="myLine"></param>
/// <returns></returns>
   
private bool isPointOnLine(IPoint pPoint, IPolyline myLine)
{
ITopologicalOperator topo = pPoint as ITopologicalOperator;
IGeometry buffer = topo.Buffer(0.00001); //缓冲一个极小的距离
topo = buffer as ITopologicalOperator;
IGeometryCollection pgeo = topo.Intersect(myLine, esriGeometryDimension.esriGeometry0Dimension) as IGeometryCollection;
bool result = false;
if (pgeo.GeometryCount > 0)
result = true;
return result;
}

/// <summary>
/// 利用三点求角度(余弦定理)
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <param name="p3"></param>
/// <returns>返回弧度值</returns>
   
private double getAngleByThreePoint(IPoint p1, IPoint p2, IPoint p3)
{
//求出三条边
double a = getDisByTwoPoint(p1, p2);
double b = getDisByTwoPoint(p1, p3);
double c = getDisByTwoPoint(p2, p3);
double cosB = (a * a + c * c - b * b) / (2 * a * c);
double angle = Math.Acos(cosB);
return angle;
}

 

/// <summary>
/// 返回两点所组成的直线的角度(平面坐标角度)
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <returns>弧度值</returns>
   
private double getAngle(IPoint p1, IPoint p2)
{
double x = p1.Y - p2.Y;
double y = p1.X - p2.X;
double tan = x / y;
double angle = Math.Atan(tan);
return angle;
}
/// <summary>
/// 返回以p1为起点,p2为终点的直线的极坐标角度(逆时针为正,顺时针为负)
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <returns>弧度值</returns>
   
private double getAngle2(IPoint p1, IPoint p2)
{
ILine pLine = new LineClass();
pLine.PutCoords(p1, p2);
return pLine.Angle;
}

/// <summary>
/// 延长线段
/// </summary>
/// <param name="passLine">传入去的线</param>
/// <param name="mode">模式,1为从FromPoint处延长,2为从ToPint处延长,3为两端延长</param>
/// <param name="dis">延长的距离</param>
/// <returns></returns>
   
public IPolyline getExtendLine(IPolyline passLine, int mode, double dis)
{
IPointCollection pPointCol = passLine as IPointCollection;
switch (mode)
{
case 1:
IPoint fromPoint = new PointClass();
passLine.QueryPoint(esriSegmentExtension.esriExtendAtFrom, -1 * dis, false, fromPoint);
pPointCol.InsertPoints(0, 1, ref fromPoint);
break;
case 2:
IPoint endPoint = new PointClass();
object missing = Type.Missing;
passLine.QueryPoint(esriSegmentExtension.esriExtendAtTo, dis + passLine.Length, false, endPoint);
pPointCol.AddPoint(endPoint, ref missing, ref missing);
break;
case 3:
IPoint fPoint = new PointClass();
IPoint ePoint = new PointClass();
object missing2 = Type.Missing;
passLine.QueryPoint(esriSegmentExtension.esriExtendAtFrom, -1 * dis, false, fPoint);
pPointCol.InsertPoints(0, 1, ref fPoint);
passLine.QueryPoint(esriSegmentExtension.esriExtendAtTo, dis + passLine.Length, false, ePoint);
pPointCol.AddPoint(ePoint, ref missing2, ref missing2);
break;
default:
return pPointCol as IPolyline;
}
return pPointCol as IPolyline;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值