本文整理汇总了C#中System.Line.getY方法的典型用法代码示例。如果您正苦于以下问题:C# Line.getY方法的具体用法?C# Line.getY怎么用?C# Line.getY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Line
的用法示例。
在下文中一共展示了Line.getY方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getPointOnLineInDistance
/// <summary>
/// Vrátí bod přímce, který od daného bodu na přímce vzdálenou o danou velikost
/// </summary>
/// <param name="line">přímka</param>
/// <param name="origin">počáteční bod</param>
/// <param name="distance">vzdálenost mezi body</param>
/// <returns></returns>
public static Point getPointOnLineInDistance(Line line, Point origin, double distance)
{
Point endPoint = new Point();
//distance^2 = (x1-x2)^2 + (y1-y2)^2
Vector<double> leftSide = Vector<double>.Build.Dense(new double[] { 0, 0, distance * distance }); // [0]x^2 + [1]x + [2]
Vector<double> xPow = Vector<double>.Build.Dense(new double[] { 1, -2 * origin.X, origin.X * origin.X }); // [0]x^2 + [1]x + [2]
Vector<double> yPow = Vector<double>.Build.Dense(new double[] { line.k * line.k, 2 * (line.q - origin.Y) * line.k, (line.q - origin.Y) * (line.q - origin.Y) }); // [0]x^2 + [1]x + [2]
Vector<double> rightSide = xPow + yPow;
Vector<double> quadraticEqutation = rightSide - leftSide;
Tuple<Complex, Complex> roots = MathNet.Numerics.FindRoots.Quadratic(quadraticEqutation.ElementAt(2), quadraticEqutation.ElementAt(1), quadraticEqutation.ElementAt(0));
//výběr toho bodu, který je vzdálenější od středu
endPoint.X = roots.Item1.Real;
if (line.vertical)
{
endPoint.Y = origin.Y + Math.Sign(origin.Y) * distance;
}
else
{
Point endPointTemp = new Point(roots.Item2.Real, 0);
Point trueOrigin = new Point(0, 0);
endPoint.Y = line.getY(roots.Item1.Real);
endPointTemp.Y = line.getY(roots.Item2.Real);
if (getDistance(trueOrigin, endPoint) < getDistance(trueOrigin, endPointTemp))
{
endPoint = endPointTemp;
}
}
return endPoint;
}