Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I'm trying to convert this equation to C# but I'm not a mathematician and I find math notation ambiguous:

See the first matrix in this article:

http://mathworld.wolfram.com/RotationMatrix.html

which has:

$$R'_\theta=\begin{bmatrix}\cos\theta & \sin\theta\\ -\sin\theta & \cos\theta \end{bmatrix} $$

That $-\sin\theta$, is that (negate sin) × angle, or negate (sin × angle)?

In math, unlike programming, there's not much use of parentheses in math equations, so what in what order should calculations be done?

share|improve this question
    
the 0 with the line is the greek letter theta and you can type it by typing \$\theta\$ –  mike vaiana Mar 12 '13 at 18:17
4  
It's sine of the angle theta, not "sine times theta" (whatever that would mean). In most programming languages you'd write it as "-sin(theta)". –  Hans Lundmark Mar 12 '13 at 18:19
1  
unfortunately there's no ambiguity here. in math, like programming, we use lots of parentheses to avoid ambiguity. –  Tyler Mar 12 '13 at 18:21
1  
Even if $\sin$ were some quantity that you were multiplying by $\theta$ (which I'll admit is what it looks like if you don't know), the order of operations wouldn't make any difference here. Negation is multiplication by $-1$, and multiplication is commutative, meaning you can multiply a list of numbers in any order and get the same result. –  Matt Pressland Mar 12 '13 at 18:30
1  
Should you need to post here again, this article has a summary of how to format mathematics, including that o with a line through it. –  MJD Mar 12 '13 at 18:43

3 Answers 3

up vote 1 down vote accepted

$\theta$ is the greek letter theta. In this context, $\theta$ represents the angle of rotation.

$\sin$ and $\cos$ are trigonometric functions. You can read about them here. In your computations, these should be evaluated first.

If you have a point on a plane represented by the tuple $(x,y)$, mathematicians refer to this as a vector in $\mathbb{R}^2$. ($\mathbb{R}^2$ is the plane of real numbers.) Matrices like $R_\theta$ are transformations which we apply to vectors. If we let $$R=\left[\begin{array}{cc}r_{11}&r_{12}\\r_{21}&r_{22}\end{array}\right]$$ and multiply this with the vector $v=\left[\begin{array}{c}v_1\\v_2\end{array}\right]$, we have $$Rv=\left[\begin{array}{cc}r_{11}&r_{12}\\r_{21}&r_{22}\end{array}\right]\left[\begin{array}{c}v_1\\v_2\end{array}\right]=\left[\begin{array}{c}r_{11}v_1+r_{12}v_2\\r_{21}v_1+r_{22}v_2\end{array}\right].$$ So in the case of $R_\theta$, you have $r_{11}=\cos\theta$, $r_{12}=-\sin\theta$, etc. Compute these before you do the matrix multiplication, and you can use the above formula.

Of course, when you get to vectors in $\mathbb{R}_3$ (associated with $3\times 3$ matrices) you will need to use a different formula. $\text{C}\#$ probably has some built in commands to deal with all this. I would recommend reading up on the documentation if you want to avoid doing the math yourself.

share|improve this answer
    
This is well-paced, comprehensive and clear, thank you. In C# there's only the most basic math building blocks and community projects tend to make up the difference. For technical reasons I can't use them, but I'm looking to improve my mathematics. –  Luke Puplett Mar 12 '13 at 19:03
1  
@LukePuplett Well, you've come to the right place, then. :) Welcome to MSE. –  Alexander Gruber Mar 12 '13 at 19:05

The expression is

$$-\sin\theta = -(\sin\theta)$$

share|improve this answer

By "the equation" I assume you mean the rotational transformation in $\mathbb{R}^2$. In general you can expand the multiplication to get a vector valued function $\vec F$, so $\vec F: \mathbb{R}^2 \rightarrow \mathbb{R}^2$, and it is defined by

$$ \vec F(x,y) = (x\cos\theta - y\sin\theta, x\sin\theta + y\cos\theta)$$

Which looks pretty much like a tuple. I'm sure there are math libraries for C# out there that have $\sin$ and $\cos$, so you can just use those.

share|improve this answer
2  
System.Math.sin and System.Math.cos in C#. –  Arkamis Mar 12 '13 at 18:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.