Нарисовать линии, начало которых исходит из точки, а заканчивается на окружности - C#
Формулировка задачи:
int accuracy = 64;
for (int i = 1; i <= accuracy; i++)
{
lineList.Add(new MyLine(line.x1, line.y1, line.x1 + (Math.Cos(((360 / accuracy) * i) * Math.PI / 180)), line.y1 + (Math.Sin(((360 / accuracy) * i) * Math.PI / 180))));
}Решение задачи: «Нарисовать линии, начало которых исходит из точки, а заканчивается на окружности»
textual
Листинг программы
public static void TangentLineMain(string[] args)
{
Circle circle = new Circle(new Point(5, 3), 4);
Point targetPoint = new Point(5, 7);
//Circle circle = new Circle(new Point(1,1), 1);
//Point targetPoint = new Point(0,0);
Point dVect = circle.Center - targetPoint;
double vectLength = dVect.Lentgh;
double vectAngle = Math.Atan2(dVect.Y, dVect.X);
//Console.WriteLine("Line Length: {0}", vectLength);
double triangleAngle = Math.Asin(circle.Radius / vectLength);
Line line1, line2;
{
double ang = vectAngle + triangleAngle;
Point p = new Point(Math.Cos(ang), Math.Sin(ang));
p *= vectLength * Math.Abs(Math.Cos(triangleAngle));
line1 = new Line(targetPoint, targetPoint + p);
}
{
double ang = vectAngle - triangleAngle;
Point p = new Point(Math.Cos(ang), Math.Sin(ang));
p *= vectLength * Math.Abs(Math.Cos(triangleAngle));
line2 = new Line(targetPoint, targetPoint + p);
}
Console.WriteLine("Line 1: {0}\nLine 2: {1}", line1, line2);
}