问题描述
我正在寻找一个数学公式,它在将 Y 绘制为 X 的函数的图表上,在指定的起点(X 的值,或者甚至更好的 X 和 Y 坐标)之前会有一定的斜率,然后之后,它将绘制一个指定半径的弧,当它到达第二个指定坡度时将结束,并且从该点开始将是第二个坡度的另一条直线.
I'm looking for a math formula that on a graph plotting Y as a function of X, before a specified starting point (a value of X, or even better, X and Y coordinates) will have a certain slope, then after that it will draw an arc of a specified radius that will end when it reaches a second specified slope, and from the point on will be another straight line of that second slope.
我知道,因为 Y 是 X 的函数,所以斜率参数需要大于 -90 度且小于 90 度;我不担心在(或超出)这些极端情况下的任何不当行为.
I'm am aware that because it's Y as a function of X, the slope parameters would need to be bigger than exactly -90 and smaller than exactly 90 degrees; i'm not worried about any misbehavior at (or beyond) those extremes.
实际上,我会更乐意使用带有起点和终点(2d 坐标)以及起点和终点坡度的公式;并且在它们之间会有两条弧线(需要时它们之间有一条直线),将两条直线无缝连接(显然终点的 X 需要大于起点的 X;我不在乎当情况并非如此时会发生).但我想这样的公式可能比我最初提出的要难得多.
Actually, i would be even happier with a formula that takes a starting and ending points (2d coordinates), and starting and ending slopes; and will have two arcs in between (with a straight line between them when needed), connecting the two straight lines seamlessly (obviously the X of the ending point needs to be bigger than the X for the starting point; i don't care what happens when that isn't the case). But i imagine such a formula might be much harder to come up with than what i asked first.
ps:弧"是指圆的一部分;例如,如果图形的两个轴具有相同的比例,则对于具有相同半径的圆,弧将具有正确的纵横比.
ps: by "arc" i mean segment of a circle; as in, if both axes of the graph have the same scale, the arcs will have the correct aspect ratio for a circle of the same radius.
推荐答案
我是这样看的:
计算
P0
作为 A + t*dA
和 B - t*dB
计算 P1
(圆心)
compute P1
(center of circle)
它是翻译线A->P0
和B->P0
的交点,垂直于半径r
.有两种可能性,所以选择正确的一种(这会导致圆形部分的角度更小).
it is intersection of translated lines A->P0
and B->P0
perpendicular by radius r
. There are 2 possibilities so choose the right one (which leads to less angle of circular part).
计算P2,P3
只是 A-P0
和 B-P0
线之间的交点以及从 P1
到它的垂直线
just an intersection between lines A-P0
and B-P0
and perpendicular line from P1
to it
曲线
// some constants first
da=P2-A;
db=B-P3;
a2=atan2(P2.x-P1.x,P2.y-P1.y);
a3=atan2(P3.x-P1.x,P3.y-P1.y);
if (a2>a3) a3-=M_PI*2.0;
dang=a3-a2;
// now (x,y)=curve(t) ... where t = <0,3>
if (t<=1.0)
{
x=A.x+t*da.x;
y=A.y+t*da.y;
}
else if (t<=2.0)
{
t=a2+((t-1.0)*dang);
x=P1.x+r*cos(t);
y=P1.y+r*sin(t);
}
else
{
t=t-2.0;
x=P3.x+t*db.x;
y=P3.y+t*db.y;
}
这篇关于绘制以直线结束的弧的公式,Y作为X的函数,起始坡度,结束坡度,起点和圆弧半径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!