本文整理匯總了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;
}