r/learnprogramming • • Apr 05 '22

Name one programming/comp sci concept you never understood and if you understand it, try to explain it to them

Name a programming concept such as virtual functions, pointers, certain algorithms, etc that you always had a hard time understanding and why.

Someone else who reads yours and does understand it, try to explain it to them to help them learn

1.6k Upvotes

738 comments sorted by

View all comments

6

u/oakskog Apr 05 '22

Transformation matrixes... If I have a 2D array of numbers, representing an image, and I want to rotate it say 30 degrees, I can use a transformation matrix? How?

2

u/CozyRedBear Apr 05 '22

A simple 2D rotation matrix multiplies the X and Y components of a vector to produce a new set of coordinates. Unless as an exercise, you often don't have to derive these matrices yourself for spatial transforms. Though if you actually multiply out a point by a valid rotation matrix, you will find that it will have had the effect of rotating that point around the origin.

It's pretty easy to imagine a scaling transform which simply multiplies each vector component by 2. Any point at the origin remains at the origin and any point off the origin is scaled by a factor of two. A translation matrix simply adds to each component.

Rotation matrices involve trigonometry and are more complex in higher dimensions. A 2D rotation matrix is very simple to derive as the 3B1B video will show.