Compute Angle to rotate

Abd4b56ff96074042dda5243e99a5d14
0
Anddos 103 Dec 16, 2009 at 18:23

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.imageshack.us/img709/1994/helpk.jpg

Thanks for reading

8 Replies

Please log in or register to post a reply.

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Dec 16, 2009 at 20:04

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.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 16, 2009 at 20:06

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.

Abd4b56ff96074042dda5243e99a5d14
0
Anddos 103 Dec 16, 2009 at 20:38

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);
340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Dec 16, 2009 at 21:01

@Anddos

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

But did you get the radians/degrees mixup as well?

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.

Abd4b56ff96074042dda5243e99a5d14
0
Anddos 103 Dec 16, 2009 at 21:10

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

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 16, 2009 at 23:39

LOL. Maybe you should try actually READING the messages people write to you. Look at this: http://www.math.rice.edu/\~pcmi/sphere/drg_txt.html. Degrees are the ones that go from 0 to 360. Radians are the ones that go from 0 to 2*pi.

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 103 Dec 17, 2009 at 06:33

I have no idea.

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Dec 17, 2009 at 11:59

@Anddos

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.