zoukankan      html  css  js  c++  java
  • Matrix矩阵连接变换应用的一个错误

    RectF rf = new RectF(100, 100, 300, 300);
    Matrix m = new Matrix();
    float centerX = 500;
    float centerY = 500;
    float scale = 1.5f;
    m.preScale(scale, scale);
    m.mapRect(rf);
    float cx = rf.centerX();
    float cy = rf.centerY();
    m.postTranslate(centerX - cx, centerY -cy);
    //m.setTranslate(centerX - cx, centerY - cy);
    m.mapRect(rf);
    


    上面这段代码目的是对原矩形以指定点(500,500)坐缩放,使用postTranslate怎么也得不到正确的值,但是使用setTranslate之后结果正确。

    原因:第一次mapRect为了得到原点缩放的中心已经对rf作了变换。而postTranslate是一个连接操作,所以整个过程的矩阵变换为:preScale -> preScale -> postTranslate,相当于对原矩形作了两次preScale操作。

  • 相关阅读:
    关于运行和调试的困惑
    初识函数
    Php的基本语法
    Apache的安装
    php的初步了解
    线程笔记
    Matlab笔记
    matlab取模与取余
    DialogFragment学习笔记
    MVP学习笔记——参考Google官方demo
  • 原文地址:https://www.cnblogs.com/fordreamxin/p/4732237.html
Copyright © 2011-2022 走看看