如何在同一直线斜率上的另一个圆后面画一个圆?
How can I draw a circle behind another circle on the same line slope?
我在行尾有一条线和一个圆圈,如下图所示:
我画了第一个圆,这个圆的中心是第一行的结尾。
我怎样才能在第一个圆圈后面并在同一直线斜率上绘制另一个圆圈?我试过这段代码:
float y2 = m * x - m * x1 + y1; //new
p1 = new PointF(x1, y1); //x and y for first line line
PointF p2 = new PointF();
p2 = new PointF(x2, y2); //make the new x,y as point
g.DrawLine(penTow, p1, p2); //this should draw line from center first circle to center of second circle
g.DrawEllipse(penOrginal,
(float)(p2.X - radius), (float)(p2.Y - radius),
(float)(radius * 2), (float)(radius * 2)); //draw the second circle and center is the end of second line
我试的时候圆圈离第一个圆圈太远了
var slope = Math.Atan2(p2.X - p1.X, p2.Y - p1.Y);
var nextX = p2.X + radus * 2 * Math.Sin(slope);
var nextY = p2.Y + radus * 2 * Math.Cos(slope);
e.Graphics.DrawEllipse(Pens.Black,
(float)(nextX - radus), (float)(nextY - radus),
(float)(radus * 2), (float)(radus * 2));
我在行尾有一条线和一个圆圈,如下图所示:
我画了第一个圆,这个圆的中心是第一行的结尾。 我怎样才能在第一个圆圈后面并在同一直线斜率上绘制另一个圆圈?我试过这段代码:
float y2 = m * x - m * x1 + y1; //new
p1 = new PointF(x1, y1); //x and y for first line line
PointF p2 = new PointF();
p2 = new PointF(x2, y2); //make the new x,y as point
g.DrawLine(penTow, p1, p2); //this should draw line from center first circle to center of second circle
g.DrawEllipse(penOrginal,
(float)(p2.X - radius), (float)(p2.Y - radius),
(float)(radius * 2), (float)(radius * 2)); //draw the second circle and center is the end of second line
我试的时候圆圈离第一个圆圈太远了
var slope = Math.Atan2(p2.X - p1.X, p2.Y - p1.Y);
var nextX = p2.X + radus * 2 * Math.Sin(slope);
var nextY = p2.Y + radus * 2 * Math.Cos(slope);
e.Graphics.DrawEllipse(Pens.Black,
(float)(nextX - radus), (float)(nextY - radus),
(float)(radus * 2), (float)(radus * 2));