# Computer graphics question

**URL:** <https://boards.straightdope.com/t/computer-graphics-question/414129>\
**Category:** Factual Questions\
**Created:** [August 2, 2007, 2:54pm UTC](https://boards.straightdope.com/t/computer-graphics-question/414129 "2007-08-02T14:54:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweeteviljesus](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@sweeteviljesus](https://boards.straightdope.com/u/sweeteviljesus)\
**Post date:** [August 2, 2007, 2:54pm UTC](https://boards.straightdope.com/t/computer-graphics-question/414129/1 "2007-08-02T14:54:37Z")

</div>

I have a small set of 2d coordinates that I want to rotate 90 degrees and I can’t remember how to do that. IIRC, it is something like (x, y) cross ((cos(theta), 0),(0, sin(theta))), but I can’t remember if that is correct. The stuff I find online is much too complicated for my purposes.

Thanks for your help,  
Rob

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [August 2, 2007, 3:00pm UTC](https://boards.straightdope.com/t/computer-graphics-question/414129/2 "2007-08-02T15:00:12Z")

</div>

[QUOTE=sweeteviljesus]  
I have a small set of 2d coordinates that I want to rotate 90 degrees and I can’t remember how to do that. IIRC, it is something like (x, y) cross ((cos(theta), 0),(0, sin(theta))), but I can’t remember if that is correct. The stuff I find online is much too complicated for my purposes.

Thanks for your help,  
Rob  
[/QUOTE]

For starting coordinates x1,y1, and a rotation of 90° CCW,  
Isn’t this just x1-\>y2, y1-\>-x2?

---

<div class="post-metadata">

**Author:** ![sweeteviljesus](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@sweeteviljesus](https://boards.straightdope.com/u/sweeteviljesus)\
**Post date:** [August 2, 2007, 3:35pm UTC](https://boards.straightdope.com/t/computer-graphics-question/414129/3 "2007-08-02T15:35:50Z")

</div>

If you mean x1-\>y1, y1-\>-x1, then no, not generally.

Thanks,  
Rob

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [August 2, 2007, 3:42pm UTC](https://boards.straightdope.com/t/computer-graphics-question/414129/4 "2007-08-02T15:42:29Z")

</div>

[QUOTE=sweeteviljesus]  
If you mean x1-\>y1, y1-\>-x1, then no, not generally.

Thanks,  
Rob  
[/QUOTE]

That’s not what I wrote.

For initial coordinates, X1,y1, a rotation without translation of 90°CCW, results in coordinates of x2,y2, such that y2 = x1, and x2 = -y1, unless I am missing something.

---

<div class="post-metadata">

**Author:** ![recessiveMeme](https://avatars.discourse-cdn.com/v4/letter/r/46a35a/32.png) [@recessiveMeme](https://boards.straightdope.com/u/recessiveMeme)\
**Post date:** [August 2, 2007, 3:51pm UTC](https://boards.straightdope.com/t/computer-graphics-question/414129/5 "2007-08-02T15:51:07Z")

</div>

In general, to rotate (x,y) to (x’,y’) you could do something like

```auto

x' = x*cos(θ) - y*sin(θ)
y' = x*sin(θ) + y*cos(θ)

```

Is that what you wanted? That’s around the origin, but you could create rotation around some arbitrary point by translating the coordinates appropriately before/after.

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [August 2, 2007, 4:11pm UTC](https://boards.straightdope.com/t/computer-graphics-question/414129/6 "2007-08-02T16:11:31Z")

</div>

[QUOTE=recessiveMeme]  
In general, to rotate (x,y) to (x’,y’) you could do something like

```auto

x' = x*cos(θ) - y*sin(θ)
y' = x*sin(θ) + y*cos(θ)

```

Is that what you wanted? That’s around the origin, but you could create rotation around some arbitrary point by translating the coordinates appropriately before/after.  
[/QUOTE]

Which for 90°, is what I wrote above…

---

<div class="post-metadata">

**Author:** ![sweeteviljesus](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@sweeteviljesus](https://boards.straightdope.com/u/sweeteviljesus)\
**Post date:** [August 2, 2007, 4:26pm UTC](https://boards.straightdope.com/t/computer-graphics-question/414129/7 "2007-08-02T16:26:22Z")

</div>

My bad. I miscalculated. Thanks for your help.

Rob

---

<div class="post-metadata">

**Author:** ![Digital\_Stimulus](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Digital\_Stimulus](https://boards.straightdope.com/u/Digital_Stimulus)\
**Post date:** [August 2, 2007, 4:26pm UTC](https://boards.straightdope.com/t/computer-graphics-question/414129/8 "2007-08-02T16:26:34Z")

</div>

[Wikipedia](http://en.wikipedia.org/wiki/Coordinate_rotation) is your friend (and confirms what **recessiveMeme** said).

On preview, given the 90 degree stipulation, it also confirms what **beowulff** said.

---

<div class="post-metadata">

**Author:** ![recessiveMeme](https://avatars.discourse-cdn.com/v4/letter/r/46a35a/32.png) [@recessiveMeme](https://boards.straightdope.com/u/recessiveMeme)\
**Post date:** [August 2, 2007, 5:05pm UTC](https://boards.straightdope.com/t/computer-graphics-question/414129/9 "2007-08-02T17:05:46Z")

</div>

[QUOTE=beowulff]  
Which for 90°, is what I wrote above…  
[/quote]  
My failure to credit your reply was an oversight on my part. Of course, you were correct. I just wanted to provide the more generalized solution in the hope that **sweeteviljesus** would recognize it as his forgotten transformation.

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [August 2, 2007, 5:14pm UTC](https://boards.straightdope.com/t/computer-graphics-question/414129/10 "2007-08-02T17:14:52Z")

</div>

[QUOTE=recessiveMeme]  
My failure to credit your reply was an oversight on my part. Of course, you were correct. I just wanted to provide the more generalized solution in the hope that **sweeteviljesus** would recognize it as his forgotten transformation.  
[/QUOTE]

No problem.  
I just hoped I didn’t miss something important…

As an aside, I once wrote code to rotate bitmaps by 90° - there are some interesting tradeoffs between algorithmic complexity, execution speed, and memory usage. Of course, these days you just use an API to do it…
