用c#编写一个程序,能够实现测角交会定点计算,包括前方交会、后方交会、侧方交会、距离交会
时间: 2023-07-10 19:10:04 浏览: 112
好的,根据您的要求,我为您提供以下代码实现:
首先,我们需要定义一个测角交会的类,包括前方交会、后方交会、侧方交会、距离交会的方法:
```csharp
class Caculation
{
//前方交会
public static PointF ForwardIntersection(PointF point1, float angle1, PointF point2, float angle2)
{
float k1 = (float)Math.Tan((90 - angle1) * Math.PI / 180);
float b1 = point1.Y - k1 * point1.X;
float k2 = (float)Math.Tan((90 - angle2) * Math.PI / 180);
float b2 = point2.Y - k2 * point2.X;
float x = (b2 - b1) / (k1 - k2);
float y = k1 * x + b1;
return new PointF(x, y);
}
//后方交会
public static PointF BackwardIntersection(PointF point1, float angle1, float distance1, PointF point2, float angle2, float distance2)
{
float k1 = (float)Math.Tan((90 - angle1) * Math.PI / 180);
float b1 = point1.Y - k1 * point1.X;
float k2 = (float)Math.Tan((90 - angle2) * Math.PI / 180);
float b2 = point2.Y - k2 * point2.X;
float x = (b2 - b1) / (k1 - k2);
float y = k1 * x + b1;
float distance3 = (float)Math.Sqrt(Math.Pow(point1.X - x, 2) + Math.Pow(point1.Y - y, 2));
float angle3 = (float)(Math.Atan2(y - point2.Y, x - point2.X) * 180 / Math.PI);
if (angle3 < 0)
angle3 += 360;
return new PointF(x, y);
}
//侧方交会
public static PointF SideIntersection(PointF point1, float angle1, float distance1, PointF point2, float angle2, float distance2)
{
float angle3 = (float)(Math.Atan2(point1.Y - point2.Y, point1.X - point2.X) * 180 / Math.PI);
if (angle3 < 0)
angle3 += 360;
float angle4 = (angle3 + angle2) % 360;
float x = point2.X + distance2 * (float)Math.Cos(angle4 * Math.PI / 180);
float y = point2.Y + distance2 * (float)Math.Sin(angle4 * Math.PI / 180);
return new PointF(x, y);
}
//距离交会
public static PointF DistanceIntersection(PointF point1, float angle1, float distance1, PointF point2, float angle2, float distance2)
{
float angle3 = (float)(Math.Atan2(point1.Y - point2.Y, point1.X - point2.X) * 180 / Math.PI);
if (angle3 < 0)
angle3 += 360;
float angle4 = (angle3 + angle2) % 360;
float x1 = point1.X + distance1 * (float)Math.Cos(angle1 * Math.PI / 180);
float y1 = point1.Y + distance1 * (float)Math.Sin(angle1 * Math.PI / 180);
float x2 = point2.X + distance2 * (float)Math.Cos(angle4 * Math.PI / 180);
float y2 = point2.Y + distance2 * (float)Math.Sin(angle4 * Math.PI / 180);
float x = (x1 + x2) / 2;
float y = (y1 + y2) / 2;
return new PointF(x, y);
}
}
```
接下来,我们可以在控制台应用程序中使用这些方法:
```csharp
class Program
{
static void Main(string[] args)
{
PointF point1 = new PointF(100, 100);
float angle1 = 30;
float distance1 = 50;
PointF point2 = new PointF(200, 200);
float angle2 = 40;
float distance2 = 70;
//前方交会
PointF forwardIntersection = Caculation.ForwardIntersection(point1, angle1, point2, angle2);
Console.WriteLine("前方交会:({0},{1})", forwardIntersection.X, forwardIntersection.Y);
//后方交会
PointF backwardIntersection = Caculation.BackwardIntersection(point1, angle1, distance1, point2, angle2, distance2);
Console.WriteLine("后方交会:({0},{1})", backwardIntersection.X, backwardIntersection.Y);
//侧方交会
PointF sideIntersection = Caculation.SideIntersection(point1, angle1, distance1, point2, angle2, distance2);
Console.WriteLine("侧方交会:({0},{1})", sideIntersection.X, sideIntersection.Y);
//距离交会
PointF distanceIntersection = Caculation.DistanceIntersection(point1, angle1, distance1, point2, angle2, distance2);
Console.WriteLine("距离交会:({0},{1})", distanceIntersection.X, distanceIntersection.Y);
Console.ReadKey();
}
}
```
这样就可以实现测角交会定点计算了。
阅读全文