由于Unity只有4x4矩阵,今天要做一个2x2矩阵的旋转,居然忘了顺序。故写下作为模版记录。

顺序:

下面是使用其进行旋转的C#代码:

public struct Position
{
public int X;
public int Y; public override string ToString() { return "X: " + X + " Y: " + Y; }
} void OnEnable()//Execute
{
var position = new Position() { X = , Y = };
var anchor = new Position() { X = , Y = }; Debug.Log("position: " + position);//print position: X: 1 Y: 0
position = Rotation(, position, anchor);
Debug.Log("position rot: " + position);//print position rot: X: 0 Y: 1
} Position Rotation(float rotValue, Position pos, Position anchor)
{
var matrix00 = Mathf.Cos(rotValue * Mathf.Deg2Rad);
var matrix01 = -Mathf.Sin(rotValue * Mathf.Deg2Rad);
var matrix10 = Mathf.Sin(rotValue * Mathf.Deg2Rad);
var matrix11 = Mathf.Cos(rotValue * Mathf.Deg2Rad); var x = (float)pos.X - anchor.X;
var y = (float)pos.Y - anchor.Y; var rx = matrix00 * x + matrix01 * y;
var ry = matrix10 * x + matrix11 * y; x = anchor.X + rx;
y = anchor.Y + ry; var intX = Mathf.RoundToInt(x);
var intY = Mathf.RoundToInt(y); return new Position() { X = intX, Y = intY };
}

2x2矩阵相乘模版的更多相关文章

  1. HDU1575Tr A(矩阵相乘与快速幂)

    Tr A hdu1575 就是一个快速幂的应用: 只要知道怎么求矩阵相乘!!(比赛就知道会超时,就是没想到快速幂!!!) #include<iostream> #include<st ...

  2. <矩阵的基本操作:矩阵相加,矩阵相乘,矩阵转置>

    //矩阵的基本操作:矩阵相加,矩阵相乘,矩阵转置 #include<stdio.h> #include<stdlib.h> #define M 2 #define N 3 #d ...

  3. 利用Hadoop实现超大矩阵相乘之我见(二)

    前文 在<利用Hadoop实现超大矩阵相乘之我见(一)>中我们所介绍的方法有着“计算过程中文件占用存储空间大”这个缺陷,本文中我们着重解决这个问题. 矩阵相乘计算思想 传统的矩阵相乘方法为 ...

  4. 利用Hadoop实现超大矩阵相乘之我见(一)

    前记 最近,公司一位挺优秀的总务离职,欢送宴上,她对我说“你是一位挺优秀的程序员”,刚说完,立马道歉说“对不起,我说你是程序员是不是侮辱你了?”我挺诧异,程序员现在是很低端,很被人瞧不起的工作吗?或许 ...

  5. POJ 2246 Matrix Chain Multiplication(结构体+栈+模拟+矩阵相乘)

    题意:给出矩阵相乘的表达式,让你计算需要的相乘次数,如果不能相乘,则输出error. 思路: 参考的网站连接:http://blog.csdn.net/wangjian8006/article/det ...

  6. ObjC语法练习 冒泡排序、选择排序、矩阵相乘

    用OC实现的冒泡排序.选择排序.矩阵相乘,纯粹是用来练习语法. 冒泡排序,程序如下: void bubbleSort() { //初始化数组 NSMutableArray *array1 = [[NS ...

  7. CUDA编程-(2)其实写个矩阵相乘并不是那么难

    程序代码及图解析: #include <iostream> #include "book.h" __global__ void add( int a, int b, i ...

  8. MapReduce实现矩阵相乘

    矩阵相乘能够查看百度百科的解释http://baike.baidu.com/view/2455255.htm?fr=aladdin 有a和b两个矩阵 a:                1   2   ...

  9. im2col:将卷积运算转为矩阵相乘

    目录 im2col实现 优缺点分析 参考 博客:blog.shinelee.me | 博客园 | CSDN im2col实现 如何将卷积运算转为矩阵相乘?直接看下面这张图,以下图片来自论文High P ...

随机推荐

  1. 一个人的旅行-Floyd

    一个人的旅行 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submis ...

  2. Canvas 唯美雨落代码实现

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  3. 使用smtp和pop3 协议收发qq邮箱实验

    email系统组件:MTA 消息传输代理,负责邮件的路由,队列和发送SMTP 简单邮件传输协议1 连接到服务器2 登陆3 发出服务请求4 退出POP:邮局协议RFC918 "邮局协议的目的是 ...

  4. python随机服务器的双线出口ip发送邮件

    #-*- coding:utf-8 -*-import smtplibimport sysimport random import socketfrom email.mime.text import ...

  5. DreamweaverCS6

    1.设置文字的格式:<font face=""></font>  字号<font size=""> 颜色<font c ...

  6. 解决Tomcat无法shutdown进程

    转自:http://my.oschina.net/yongyi/blog/405198 问题分析 这个在windows下没有碰到过,因为此前跑Tomcat都是以服务而不是命令脚本的形式跑的,而且已经换 ...

  7. vim - Putting the current file on the Windows clipboard

    http://vim.wikia.com/wiki/VimTip432 command! Copyfile let @*=substitute(expand("%:p"), '/' ...

  8. stty--设置终端线

    stty - chang and print terminal line settings SYNOPSIS stty [-F DEVICE | --file=DEVICE] [SETTING]... ...

  9. soap ui 进行接口测试

    [前置条件] 1. 电脑上已安装soap UI 5.0 2. 电脑上已安装eclipse. JDK1.6.tomcat 3. eclipse已经成功的配置JDK1.6.tomcat [操作步骤] 1. ...

  10. HTML5本地存储之localStorage

    存入本地中:localStorage.setItem('Code',‘10001’) 获取:localStorage.getItem('Code')