用比例因子绘制点的图形
我使用以下内容集中缩放图表上的一个框:
var x1 = (this.width - (this.image.width * this.scale)) / 2 + this.origin.x;
var y1 = (this.height - (this.image.height * this.scale)) / 2 + this.origin.y;
var x2 = (this.image.width * this.scale);
var y2 = (this.image.height * this.scale);
context.drawImage(this.image, x1, y1, x2, y2);
现在我需要能够缩放该图表上的单个点。该点具有原点 x / y、点 x / y 以及当前级别的比例因子 (this.scale)。如何将此比例因子转换为具有给定比例的盒子上的点?
I am centrally scaling a box on a graph with the following:
var x1 = (this.width - (this.image.width * this.scale)) / 2 + this.origin.x;
var y1 = (this.height - (this.image.height * this.scale)) / 2 + this.origin.y;
var x2 = (this.image.width * this.scale);
var y2 = (this.image.height * this.scale);
context.drawImage(this.image, x1, y1, x2, y2);
Now I need to be able to scale a single point on that graph. The point has an origin x / y, point x / y, and a scale factor (this.scale) at the current level. How can I translate this scale factor into a point on the box with the given scale?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的问题是 - 一个点已经给出了坐标
x,y
并且你需要想出新的 x 和 y 坐标a, b
以便它在缩放框中的位置与整个图中的位置相同。该点与原点水平距离为
x
个单位,您需要它距离新原点为x/scale
个单位。因此,
a = x/scale + x1
(因为新原点的坐标为x1, y1
),类似地,该点垂直于原点,并且您需要它距新原点为
y/scale
单位。和
b = y/scale + y1
我想我可能误解了新原点的位置(框的左角,但如果我简单地替换
x1
和y1
与新原点的坐标)I think your question is - a point has given coordinates
x,y
and you need to come up with the new x and y co-ordinatesa, b
so that its in the same place within the scaled box as it was in the whole graph.The point is
x
units away horizontally from the origin, and you need it to bex/scale
units from the new origin.So,
a = x/scale + x1
( because the new origin has coordinatesx1, y1
)similarly, the point is
y
units vertically from the origin, and you need it to bey/scale
units from the new origin.and
b = y/scale + y1
I think i may have misunderstood where the new origin is (the left corner of the box, but if I have then simply replace
x1
andy1
with the coordinates of the new origin)