/*
软件作者:https://xuhss.com/oxox/pro
*/
importPackage(android.graphics);
log(new Canvas());
var matrix= new Matrix();
log(matrix);
matrix.setTranslate(100,100);
//矩阵坐标移动(x偏移,y偏移)
log(matrix);
matrix.postScale(0.5,0.5);
//矩阵缩放(sx,sy,x…,y…);
log(matrix);
matrix.postRotate(30);
//矩阵旋转(Y,x…,y…)
log(matrix);
matrix.postSkew(1,2);
//错切(x,y,x…,y…)
log(matrix);
log(matrix.toShortString());
//{name:"getValues",type:"function",string:"function getValues() {/*void getValues(float[])*/}"}
//var buffer = java.lang.reflect.Array.newInstance( java.lang.Float.TYPE, 3);
var ary=util.java.array("float", 8);
// var ary=[1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0];
matrix.mapPoints(ary,ary);
log(ary);
/*
{name:
"mapPoints",
type:
"function",
string:
"function mapPoints() {
void mapPoints(float[],float[])
void mapPoints(float[],int,float[],int,int)
void mapPoints(float[])
}
"}
*/
/*
Matrix matrix1 = new Matrix();
Matrix matrix2 = new Matrix();
matrix1.setTranslate(1,2);
matrix2.setTranslate(2,2);
// 输出:matrix1 == matrix2:false
System.out.println("matrix1 == matrix2:" + matrix1.equals(matrix2));
*/
/*Matrix matrix = new Matrix();
// 输出:+号相连:Matrix{[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]}
System.out.println("+号相连:" + matrix);
// 输出:Matrix{[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]}
System.out.println("toString:" + matrix.toString());
// 输出:[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]
System.out.println("toShortString:" + matrix.toShortString());
*/
/*
public static final int MSCALE_X = 0; //!< use with getValues/setValues
public static final int MSKEW_X = 1; //!< use with getValues/setValues
public static final int MTRANS_X = 2; //!< use with getValues/setValues
public static final int MSKEW_Y = 3; //!< use with getValues/setValues
public static final int MSCALE_Y = 4; //!< use with getValues/setValues
public static final int MTRANS_Y = 5; //!< use with getValues/setValues
public static final int MPERSP_0 = 6; //!< use with getValues/setValues
public static final int MPERSP_1 = 7; //!< use with getValues/setValues
public static final int MPERSP_2 = 8; //!< use with getValues/setValues
方法示例:
Matrix matrix = new Matrix();
// matrix = [1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]
System.out.println("matrix = " + matrix.toShortString());
float[] values = new float[9];
matrix.getValues(values);
// matrix转换成数组后 = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
System.out.println("matrix转换成数组后 = " + Arrays.toString(values));
// 为matrix赋值
values [Matrix.MTRANS_X] = 2;
values [Matrix.MTRANS_Y] = 3;
matrix.setValues(values);
// matrix = [1.0, 0.0, 2.0][0.0, 1.0, 3.0][0.0, 0.0, 1.0]
System.out.println("matrix = " + matrix.toShortString());
*/
/*
// [1.0, 0.0, 0.0]
// [0.0, 1.0, 0.0]
// [0.0, 0.0, 1.0]
Matrix matrix = new Matrix();
Matrix matrix1 = new Matrix();
Matrix matrix2 = new Matrix();
// [1.0, 0.0, 0.0] [2.0, 3.0, 4.0]
// [0.0, 1.0, 0.0] -> [2.0, 0.0, 0.0]
// [0.0, 0.0, 1.0] [1.0, 1.0, 1.0]
matrix1.setValues(new float[]{2.0f,3.0f, 4.0f,
2.0f,0.0f, 0.0f,
1.0f,1.0f,1.0f});
// [1.0, 0.0, 0.0] [2.0, 5.0, 4.0]
// [0.0, 1.0, 0.0] -> [3.0, 0.0, 0.0]
// [0.0, 0.0, 1.0] [1.0, 2.0, 1.0]
matrix2.setValues(new float[]{2.0f,5.0f, 4.0f,
3.0f,0.0f, 0.0f,
1.0f,2.0f,1.0f});
// [2.0, 3.0, 4.0] [2.0, 5.0, 4.0] [17.0, 18.0, 12.0]
// [2.0, 2.0, 0.0](matrix1) * [3.0, 0.0, 0.0](matrix2) = [4.0, 10.0, 8.0 ] (matrix)
// [1.0, 1.0, 1.0] [1.0, 2.0, 1.0] [6.0, 7.0, 5.0 ]
matrix.setConcat(matrix1,matrix2);
*/
/*
//距离
// 一个半径为100.0f的圆,放大1倍后,半径也将增大一倍。据说用在画布中的圆随画布大小变化时
float radius = 100.0f;
float radiusAfterMatrix;
Matrix matrixRadius = new Matrix();
matrixRadius.setScale(2,2);
radiusAfterMatrix = matrixRadius.mapRadius(radius);
// 输出:radius=200.0
System.out.println("radius=" + radiusAfterMatrix);
*/
/*
// =======================
// mapPoints(float[] pts)
// =======================
// 运算后的结果会保存在pts数组中,原pts数组中的内容会被覆盖
// 1.《点的移动》,对于任意点(Xn,Yn),x轴方向平移dx,y轴方向平移dy后有:
// Xn = Xn + dx
// Yn = Yn + dy
float[] ptsTrans = {6,2};
Matrix matrixTrans = new Matrix();
matrixTrans.setTranslate(-2,2);
matrixTrans.mapPoints(ptsTrans);
// 输出:trans=[4.0, 4.0]
System.out.println("trans=" + Arrays.toString(ptsTrans));
// 2.《点的放大》,对于任意点(Xn,Yn),绕点(px,py)x轴、y轴方向分别放大sx倍、sy倍后,有:
// Xn = Xn * sx + (px - px * sx)
// Yn = Yn * sy + (py - sy * py)
float[] ptsScale = {2,3};
Matrix matrixScale = new Matrix();
matrixScale.setScale(3,6,2,2);
matrixScale.mapPoints(ptsScale);
// 输出:scale=[2.0, 8.0]
System.out.println("scale=" + Arrays.toString(ptsScale));
// 3.《点的旋转》,对于任意点(Xn,Yn),绕点(px,py)旋转a度后,有:
// Xn = (Xn - px) * cos(a) - (Yn - py) * sin(a) + px
// Yn = (Xn - px) * sin(a) + (Yn - py) * cos(a) + py
float[] ptsRotate = {6,6};
Matrix matrixRotate = new Matrix();
matrixRotate.preRotate(90,2,3);
matrixRotate.mapPoints(ptsRotate);
// 输出:rotate=[-1.0,7.0]
System.out.println("rotate=" + Arrays.toString(ptsRotate));
// 4.《点的错切》,对于任意点(Xn,Yn),绕点(px,py)x轴、y轴方向分别错切kx、ky后,有:
// Xn = Xn + kx(Yn - py)
// Yn = Yn + ky(Xn - px)
float[] ptsSkew = {3,2};
Matrix matrixSkew = new Matrix();
matrixSkew.setSkew(2,3,6,8);
matrixSkew.mapPoints(ptsSkew);
// 输出:skew=[-9.0,-7.0]
System.out.println("skew=" + Arrays.toString(ptsSkew));
// ===================================
// mapPoints(float[] dst, float[] src)
// ===================================
// 运算后的结果保存在dst数组中,原src数组中的内容会保留
float[] src = {2,3,3,3};
float[] dst = new float[src.length];
Matrix matrixDstSrc = new Matrix();
matrixDstSrc.setTranslate(2,3);
matrixDstSrc.mapPoints(dst,src);
// 输出:dst=[4.0,6.0,5.0,6.0]
System.out.println("dst=" + Arrays.toString(dst));
// 输出:src=[2.0,3.0,3.0,3.0]
System.out.println("src=" + Arrays.toString(src));
// ==============================================================================
// mapPoints(float[] dst, ---- 计算结果存放数组
// int dstIndex, ---- dst数组存放计算结果时起始下标
// float[] src, ---- 计算的源数组
// int srcIndex, ---- 源数组计算时起始下标
// int pointCount ---- 从起始下标开始一共要计算多少个点
// )
// ==============================================================================
// 运算后的结果保存在dst数组中
float[] src1 = {2,3,3,3,2,3};
float[] dst1 = new float[]{6,6,6,6,6,6};
Matrix matrixDstSrc1 = new Matrix();
matrixDstSrc1.setTranslate(1,1);
// 1)从src1下标为2的位置开始计算,计�
AutoJs源码-研究矩阵
需积分: 1 41 浏览量
2022-11-16
04:24:07
上传
评论
收藏 3KB 7Z 举报
[虚幻私塾】
- 粉丝: 335
- 资源: 1559
最新资源
- 基于STC15F104E系列单片机的EEPROM应用程序测试例程KEIL工程源码.zip
- 基于STC15F104E系列单片机的串口通讯应用程序测试例程KEIL工程源码.zip
- java-leetcode题解之第844题比较含退格的字符串.zip
- java-leetcode题解之第824题山羊拉丁文.zip
- java-leetcode题解之第819题最常见的单词.zip
- 基于STC15F104E系列单片机产生PWM信号测试例程KEIL工程源码.zip
- STC15F104E系列单片机-串口、外部中断、掉电存储、定时器同时应用程序KEIL工程源码.zip
- java-leetcode题解之第686题重复叠加字符串匹配.zip
- java-leetcode题解之第680题验证回文串II.zip
- java-leetcode题解之第557题反转字符串中的单词III.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈