# How To Rotate A 3d Object (given A Vector)?

**URL:** https://forum.highend3d.com/t/how-to-rotate-a-3d-object-given-a-vector/3464
**Category:** Maya
**Tags:** mel
**Created:** [December 11, 2005, 11:08am UTC](https://forum.highend3d.com/t/how-to-rotate-a-3d-object-given-a-vector/3464 "2005-12-11T11:08:59Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![notabutb](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/n/e5b9ba/32.png) [@notabutb](https://forum.highend3d.com/u/notabutb)
#### Post date: [December 11, 2005, 11:08am UTC](https://forum.highend3d.com/t/how-to-rotate-a-3d-object-given-a-vector/3464/1 "2005-12-11T11:08:59Z")

</div>

Hi! i would like to rotate an object according to a given vector, using MEL. Any recommendations on how this task might be achieved?

---

<div class="post-metadata">

### Author: ![failure](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/f08c70/32.png) [@failure](https://forum.highend3d.com/u/failure)
#### Post date: [December 11, 2005, 11:30am UTC](https://forum.highend3d.com/t/how-to-rotate-a-3d-object-given-a-vector/3464/2 "2005-12-11T11:30:04Z")

</div>

Why do you need to rotate it and what would that vector represent? Rotation in 3d space is not fully defined with just one vector. Consider using aim constraint.

---

<div class="post-metadata">

### Author: ![notabutb](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/n/e5b9ba/32.png) [@notabutb](https://forum.highend3d.com/u/notabutb)
#### Post date: [December 11, 2005, 11:57am UTC](https://forum.highend3d.com/t/how-to-rotate-a-3d-object-given-a-vector/3464/3 "2005-12-11T11:57:20Z")

</div>

QUOTE(failure @ 12/11/05, 07:30 PM)  
Why do you need to rotate it and what would that vector represent? Rotation in 3d space is not fully defined with just one vector. Consider using aim constraint.  
[snapback]222076[/snapback]

Sorry that my question is unclear. i would like to change my question to "i would like to find out the angle between two vectors u and v using the mathematical formula inverse cosine[(u.v)/(|u||v|)]. Is there any MEL command, such as inverse cosine, that can help me to calculate it?"

---

<div class="post-metadata">

### Author: ![failure](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/f08c70/32.png) [@failure](https://forum.highend3d.com/u/failure)
#### Post date: [December 11, 2005, 12:38pm UTC](https://forum.highend3d.com/t/how-to-rotate-a-3d-object-given-a-vector/3464/4 "2005-12-11T12:38:36Z")

</div>

Why don't you look into reference?

---

<div class="post-metadata">

### Author: ![notabutb](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/n/e5b9ba/32.png) [@notabutb](https://forum.highend3d.com/u/notabutb)
#### Post date: [December 11, 2005, 1:13pm UTC](https://forum.highend3d.com/t/how-to-rotate-a-3d-object-given-a-vector/3464/5 "2005-12-11T13:13:50Z")

</div>

QUOTE(failure @ 12/11/05, 08:38 PM)  
Why don't you look into reference?  
[snapback]222078[/snapback]

i have come across cos command in Maya Help. But no inverse cos command is found. So im wondering if there are any other commands that might be helpful. Anyway, thank you ![](http://www.highend3d.com/boards/style_emoticons/<#EMO_DIR#>/smile.gif)

---

<div class="post-metadata">

### Author: ![failure](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/f08c70/32.png) [@failure](https://forum.highend3d.com/u/failure)
#### Post date: [December 11, 2005, 1:17pm UTC](https://forum.highend3d.com/t/how-to-rotate-a-3d-object-given-a-vector/3464/6 "2005-12-11T13:17:57Z")

</div>

read the description for cos

btw there's angle command which returns angle between two vectors so you don't need to calculate it via dot product.

CODE  
rad\_to\_deg( angle( \<\>, \<\> ) );

---

<div class="post-metadata">

### Author: ![notabutb](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/n/e5b9ba/32.png) [@notabutb](https://forum.highend3d.com/u/notabutb)
#### Post date: [December 11, 2005, 1:29pm UTC](https://forum.highend3d.com/t/how-to-rotate-a-3d-object-given-a-vector/3464/7 "2005-12-11T13:29:18Z")

</div>

QUOTE(failure @ 12/11/05, 09:17 PM)  
read the description for cos

btw there's angle command which returns angle between two vectors so you don't need to calculate it via dot product.

CODE  
rad\_to\_deg( angle( \<\>, \<\> ) );

[snapback]222080[/snapback]

Thanks a lot. i have also just come across the angle command too. This is probably what i need. ![](http://www.highend3d.com/boards/style_emoticons/<#EMO_DIR#>/laugh.gif)

---

<div class="post-metadata">

### Author: ![failure](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/f08c70/32.png) [@failure](https://forum.highend3d.com/u/failure)
#### Post date: [December 11, 2005, 2:01pm UTC](https://forum.highend3d.com/t/how-to-rotate-a-3d-object-given-a-vector/3464/8 "2005-12-11T14:01:26Z")

</div>

If you want to map one vector onto another less painful way is to find angle ( which you now know how ) and rotation axis ( using cross product ). Then construct a quaternion. You can easily make a transformation matrix out of quaternion.

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [December 11, 2005, 11:05pm UTC](https://forum.highend3d.com/t/how-to-rotate-a-3d-object-given-a-vector/3464/9 "2005-12-11T23:05:17Z")

</div>

oe you can use axis angle... It can sometimes be easier to visualize than quarteronion. TOugh quarteronion handles the siungularity WAY better.

Nonetheless i do tend to use axisangle aon occasion.
