Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#偏移垂直于给定线段的点_C# - Fatal编程技术网

C#偏移垂直于给定线段的点

C#偏移垂直于给定线段的点,c#,C#,我有一个由两点D定义的线段(一个使用双精度而不是浮点数的自定义类型,正如C#中的数学使用双精度):p1(.541,41.929),p2(363.736,88.48)-假设直线将倾斜 在不可预测的时间间隔内,我需要将垂直于线段的偏移点设置为可变距离,比如0.125、0.25等等 似乎所有的例子都假设你总是需要这个垂直点以中点为基础 我已通过以下方式解决p3问题:( 0.25的返回点是(91.339,53.566)。我已经在cad中验证了这一点,以满足我的要求 在我的一生中,我无法弄清楚的是,如何从

我有一个由两点D定义的线段(一个使用双精度而不是浮点数的自定义类型,正如C#中的数学使用双精度):p1(.541,41.929),p2(363.736,88.48)-假设直线将倾斜

在不可预测的时间间隔内,我需要将垂直于线段的偏移点设置为可变距离,比如0.125、0.25等等

似乎所有的例子都假设你总是需要这个垂直点以中点为基础

我已通过以下方式解决p3问题:(

0.25的返回点是(91.339,53.566)。我已经在cad中验证了这一点,以满足我的要求

在我的一生中,我无法弄清楚的是,如何从直线上得到一个垂直点5(只是为了使它变圆)


我期望的结果是p4(90.705,58.526)

我已经提出了一个可行的C#实现:

/// <summary>
/// Create a perpendicular offset point at a position located along a line segment.
/// </summary>
/// <param name="a">Input. PointD(x,y) of p1.</param>
/// <param name="b">Input. PointD(x,y) of p2.</param>
/// <param name="position">Distance between p1(0.0) and p2 (1.0) in a percentage.</param>
/// <param name="offset">Distance from position at 90degrees to p1 and p2- non-percetange based.</param>
/// <param name="c">Output of the calculated point along p1 and p2. might not be necessary for the ultimate output.</param>
/// <param name="d">Output of the calculated offset point.</param>
private void PerpOffset(PointD a, PointD b, double position, double offset, out PointD c, out PointD d)
{
    //p3 is located at the x or y delta * position + p1x or p1y original.
    PointD p3 = new PointD(((b.X - a.X) * position) + a.X, ((b.Y - a.Y) * position) + a.Y);

    //returns an angle in radians between p1 and p2 + 1.5708 (90degress).
    double angleRadians = Math.Atan2(a.Y - b.Y, a.X - b.X) + 1.5708;

    //locates p4 at the given angle and distance from p3.
    PointD p4 = new PointD(p3.X + Math.Cos(angleRadians) * offset, p3.Y + Math.Sin(angleRadians) * offset);

    //send out the calculated points
    c = p3;
    d = p4;
}

我提出了一个可行的C#实现:

/// <summary>
/// Create a perpendicular offset point at a position located along a line segment.
/// </summary>
/// <param name="a">Input. PointD(x,y) of p1.</param>
/// <param name="b">Input. PointD(x,y) of p2.</param>
/// <param name="position">Distance between p1(0.0) and p2 (1.0) in a percentage.</param>
/// <param name="offset">Distance from position at 90degrees to p1 and p2- non-percetange based.</param>
/// <param name="c">Output of the calculated point along p1 and p2. might not be necessary for the ultimate output.</param>
/// <param name="d">Output of the calculated offset point.</param>
private void PerpOffset(PointD a, PointD b, double position, double offset, out PointD c, out PointD d)
{
    //p3 is located at the x or y delta * position + p1x or p1y original.
    PointD p3 = new PointD(((b.X - a.X) * position) + a.X, ((b.Y - a.Y) * position) + a.Y);

    //returns an angle in radians between p1 and p2 + 1.5708 (90degress).
    double angleRadians = Math.Atan2(a.Y - b.Y, a.X - b.X) + 1.5708;

    //locates p4 at the given angle and distance from p3.
    PointD p4 = new PointD(p3.X + Math.Cos(angleRadians) * offset, p3.Y + Math.Sin(angleRadians) * offset);

    //send out the calculated points
    c = p3;
    d = p4;
}

你的问题是什么?如何解决p4。我使用cad来找到解决方案。一个数学问题,而不是C#。雷阳-虽然它可能更基于数学,但有大量现有的C#线程被错误地回答-因此,除非你有一个可行的C#实现这个假设的数学问题,否则你的评论是完全有用的ess,我向你提出挑战,让你把钱放在嘴上,拿出有效的解决方案。我投票决定把这个问题作为离题题来结束,因为这是一个数学问题,而不是一个编程问题。你的问题是什么?如何解决p4。我用cad来找到解决方案。一个数学问题,而不是C#。雷阳-虽然它可能更像是m基于ath,有大量现有的C#线程没有得到正确的回答-因此,除非你对这个假设的数学问题有一个有效的C#实现,否则你的评论是完全没有用的,我要求你把钱放在嘴上,并提出有效的解决方案。我投票结束这个问题,作为主题b因为这是一个数学问题,而不是编程问题。
public class PointD
{
    public double X { get; set; }
    public double Y { get; set; }

    public float Xf { get { return (float)X; } }
    public float Yf { get { return (float)Y; } }

    public PointF PointF { get { return new PointF(Xf, Yf); } }

    public PointD()
    { }

    public PointD(double cX, double cY)
    {
        X = cX;
        Y = cY;
    }

    public override string ToString()
    {
        return string.Format("[{0}, {1}]", X, Y);
    }
}