# Compute Angle to rotate

8 replies to this topic

### #1Anddos

Valued Member

• Members
• 177 posts

Posted 16 December 2009 - 06:23 PM

I understand i need to get the Dotproduct of the 2 vectors and then set the rotationz for the bottom teapot so it looks up at the other above it ,do you have to convert the DotProduct to radians as its in degrea's?

vectors are

D3DXVECTOR3 TeaPotPos(0.0f,-3.0f,-10.0f);
D3DXVECTOR3 TeaPotPos2(0.0f,3.0f,-10.0f);

pic included

http://img709.images.../1994/helpk.jpg

### #2.oisyn

DevMaster Staff

• Moderators
• 1842 posts

Posted 16 December 2009 - 08:04 PM

First of all, the angle in your picture is 90 degrees, not 180 radians. There are only 2pi radians in a circle, so 180 radians doesn't make sense. Secondly, forget degrees, start thinking in radians. Everything in math programming is always in radians.
-
Currently working on: the 3D engine for Tomb Raider.

### #3Reedbeta

DevMaster Staff

• 5308 posts
• LocationSanta Clara, CA

Posted 16 December 2009 - 08:06 PM

Also the dot product doesn't return degrees or radians. To get an angle out of it, first you have to normalize the two vectors you're dotting. Then the dot product is the cosine of the angle between them. Call acos() and you've got the angle in radians.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #4Anddos

Valued Member

• Members
• 177 posts

Posted 16 December 2009 - 08:38 PM

Thank you so much i will try that now , yeh it was a typo saying 180 , i did mean 90 :)

so i try this, dosen't look like its done what i want
Angle says 0.761013


D3DXVECTOR3 TeaPot1Pos(0.0f,2.0f,-5.0f);

D3DXVECTOR3 TeaPot2Pos(0.0f,-2.0f,-5.0f);

D3DXVec3Normalize (&TeaPot1Pos,&TeaPot1Pos);

D3DXVec3Normalize (&TeaPot2Pos,&TeaPot2Pos);

float Dot = D3DXVec3Dot(&TeaPot1Pos,&TeaPot2Pos);

float Angle = acos(Dot); //should be 90

D3DXMATRIX TeaPot1Matrix;

D3DXMatrixTranslation(&TeaPot1Matrix,TeaPot1Pos.x,TeaPot1Pos.y,TeaPot1Pos.z);

D3DXMATRIX TeaPot1Rot;

D3DXMatrixRotationZ(&TeaPot1Rot,Angle);

d3ddev->SetTransform(D3DTS_WORLD,&(TeaPot1Rot * TeaPot1Matrix));

meshTeapot->DrawSubset(0);

D3DXMATRIX TeaPot2Matrix;

D3DXMatrixTranslation(&TeaPot2Matrix,TeaPot2Pos.x,TeaPot2Pos.y,TeaPot2Pos.z);

d3ddev->SetTransform(D3DTS_WORLD,&TeaPot2Matrix);

meshTeapot2->DrawSubset(0);



### #5.oisyn

DevMaster Staff

• Moderators
• 1842 posts

Posted 16 December 2009 - 09:01 PM

Anddos said:

Thank you so much i will try that now , yeh it was a typo saying 180 , i did mean 90
But did you get the radians/degrees mixup as well?

Quote

float Angle = acos(Dot); //should be 90
No, that should be pi/2, as we're talking radians, not degrees. I get the feeling you have your definitions of radians and degrees reversed.
-
Currently working on: the 3D engine for Tomb Raider.

### #6Anddos

Valued Member

• Members
• 177 posts

Posted 16 December 2009 - 09:10 PM

ok sorry , so it should be 180 radians,Angle says 0.761013, should it not be 180 float

### #7Reedbeta

DevMaster Staff

• 5308 posts
• LocationSanta Clara, CA

Posted 16 December 2009 - 11:39 PM

LOL. Maybe you should try actually READING the messages people write to you. Look at this: http://www.math.rice...re/drg_txt.html. Degrees are the ones that go from 0 to 360. Radians are the ones that go from 0 to 2*pi.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #8rouncer

Senior Member

• Members
• 2722 posts

Posted 17 December 2009 - 06:33 AM

I have no idea.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

### #9.oisyn

DevMaster Staff

• Moderators
• 1842 posts

Posted 17 December 2009 - 11:59 AM

Anddos said:

ok sorry , so it should be 180 radians,Angle says 0.761013, should it not be 180 float
Christ. At least TRY to read my post. NO NOT 180 RADIANS, IF YOU SAY 180 YOU MEAN DEGREES. BUT 180 DEGREES IS THE SAME AS 3.1415 RADIANS.

But indeed, I haven't looked at the actual coordinates at first, but the angle seems correct to me (0.761013 radians equals roughly 43.6 degrees). Just flipping a vector about the y-axis doesn't mean it's rotated 180 degrees. I get the feeling you're actually thinking in 2D, while your vectors are in 3D.