且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

以窗体形式绘制回旋曲线

更新时间:2023-12-06 16:11:04

嗯,这不是火箭科学:你必须翻译和缩放你的图像(也可以反转y轴)。

假设你的油漆区域有coords:左上角= {X0,Y0} 右下角{X1,Y1} 然后

Well, it is not rocket science: you have to translate and scale your image (inverting the y-axis as well).
Supposing your paint area havs coords: top-left = {X0,Y0}, bottom-right {X1,Y1} then
xf = X0 + (x + 1) * (X1 - X0) / 2
yf = Y1 - (y + 1) * (Y1 - Y0) / 2

其中 {x,y} 是计算的回旋点, {xf,yf} 是它的变形表兄。

Where {x,y} is the computed clothoid point and {xf,yf} is its transformed cousin.


你可以对x和y值应用比例/偏差函数。

You can apply a scale/bias function to x and y values.
// We have f() -> (x, y)
// x Є [-1, 1], y Є [-1, 1]

double x, y; // These variables have their values assigned by the function

double width = panel.Width / 2d;
double height = panel.Height / 2d;

// Scale x in the range [-width / 2, width / 2]
double newX = x * width; 
// Bias x in the range [0, width]
newX += width;

// Similarly

// Scale y in the range [-height / 2, height / 2]
double newY = y * height;
// Bias y in the range [0, height]
newY += height;



如果您的面板不是方形,并且您不希望生成的曲线被缩放,那么您必须选择两个因子宽度和高度,并使用此值作为x和y的缩放系数。



希望这会有所帮助。亲切。


In case your panel is not square, and you do not want the resulting curve to be distorded, then you have to choose the least between both factors width and height, and use this one as the scaling factor for x and y.

Hope this helps. Kindly.


感谢您的建议,有没有办法增加像素或坐标的大小。因为我希望-1到0和0到1是宽可见的,这样我就可以绘制曲线。
Thanks for your suggestion, is there any way to increase size of pixel or co ordinates. because i want -1 to 0 and 0 to 1 to be wide visible so that i could draw curve.