开发者

Graphing a point with a scale factor

I am centrally scaling a box on a graph with th开发者_JS百科e 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?


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜