用比例因子绘制点的图形

发布于 2024-12-10 18:59:57 字数 437 浏览 0 评论 0原文

我使用以下内容集中缩放图表上的一个框:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷你仙 2024-12-17 18:59:57

我认为你的问题是 - 一个点已经给出了坐标 x,y 并且你需要想出新的 x 和 y 坐标 a, b 以便它在缩放框中的位置与整个图中的位置相同。

该点与原点水平距离为 x 个单位,您需要它距离新原点为 x/scale 个单位。

因此,a = x/scale + x1(因为新原点的坐标为x1, y1),

类似地,该点垂直于原点,并且您需要它距新原点为 y/scale 单位。

b = y/scale + y1

我想我可能误解了新原点的位置(框的左角,但如果我简单地替换 x1y1 与新原点的坐标)

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-ordinates a, 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 be x/scale units from the new origin.

So, a = x/scale + x1 ( because the new origin has coordinates x1, y1 )

similarly, the point is y units vertically from the origin, and you need it to be y/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 and y1 with the coordinates of the new origin)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文