从原始框和缩放框计算变换原点 [英] Calculate transform-origin from original and scaled boxes

查看:28
本文介绍了从原始框和缩放框计算变换原点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于原始的 rect1 (x1, y1, w1, h1) 和已知的缩放 rect2 (x2, y2, w2, h2) 找出使用什么变换原点的公式是什么?我需要一个可重复使用的公式,因为 rect2 可以放在任何地方.

Based on an original rect1 (x1, y1, w1, h1) and a known scaled rect2 (x2, y2, w2, h2) what is the formula to find out what transform-origin was used? I need a reusable formula because rect2 can be positioned anywhere.

换句话说,我知道一个小矩形的边界,并希望它通过应用正确的变换原点坐标(以 px 或 % 为单位)过渡到一个更大的矩形.

Put another way, I know the bounds of a little rectangle and want it to transition to a bigger rectangle by applying the correct transform-origin coordinates (in px or %).

推荐答案

在简单的比例尺中,变换原点的 x 坐标为 tx 的距离 x1 -> tx 和 tx -> (x1+w1) 之间的比率保持不变秤后相同.换句话说:

In a simple scale, the ratios between the distances x1 -> tx and tx -> (x1+w1) where the transform origin's x coordinate is tx remain the same after the scale. In order words:

(tx-x1)/w1 = (tx-x2)/w2

(tx-x1)/w1 = (tx-x2)/w2

解决 tx,你得到:

tx = (w2/(w2-w1)) * (x1 - (x2 * w1)/w2)

tx = (w2/(w2-w1)) * (x1 - (x2 * w1)/w2)

类似的公式会产生你的 ty.

Analagous formula will yield your ty.

(请注意,如果您将透视与 az 变换一起使用,那么此公式将是错误的,如果您也不知道您的透视原点,那么我相信结果将是不确定的,因为透视的组合将是无限的原点和变换原点将产生相同的结果.如果你知道透视原点,那么数学仍然相当复杂.)

(Note that if you're using perspective with a z transform then this formula will be wrong, and if you don't know your perspective origin either, then I believe the result will be indeterminate because there will be infinite combinations of perspective origin and transform origin that will yield the same result. If you do know the perspective origin then the math is still pretty complicated.)

这篇关于从原始框和缩放框计算变换原点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆