繁体   English   中英

如何缩放点?

[英]How to scale about point?

我在PAffineTransform找到以下代码:

/**
     * Scales the transform about the given point by the given scale.
     * 
     * @param scale to transform the transform by
     * @param x x coordinate around which the scale should take place
     * @param y y coordinate around which the scale should take place
     */
    public void scaleAboutPoint(final double scale, final double x, final double y) {

        //TODO strange order

        translate(x, y);
        scale(scale, scale);
        translate(-x, -y);
    }

进行反向操作是否正确:

        translate(-x, -y);
        scale(scale, scale);
        translate(x, y);

所有使用的方法都与AffineTransform中的相同。

UPDATE

我的错。

顺序变换修改意味着从右边开始矩阵乘法。 因此,最后应用的修改在转换时首先起作用,因为转换是从左开始的矩阵乘法。

PAffineTransform的顺序与以下事实有关: PAffineTransform中的每个节点都有一个仿射变换,该仿射变换定义了该节点的局部坐标系。

通常,要缩放特定点,请先平移对象,以使该点位于原点。 然后执行缩放,然后执行原始平移的逆操作以将固定点移回其原始位置。

PNode有其自己的局部坐标系,其原点为(0,0)。 因此,在节点上执行scaleAboutPoint()时,在PAffineTransform定义的顺序很有意义。 首先,平移到该点,使其成为新的原点,然后缩放,然后反向平移。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM