How can I find direction with known 2 projection angles on xz and yz planes?
I think 'A' vector3 direction would beQuaternion.AngleAxis( A, transform.up) * transform.forward
&
'B' vector3 direction would beQuaternion.AngleAxis( -B, transform.right) * transform.forward
But I dont know the vector3 direction of 'u' Vector.
I need direction for Raycasting.
Can someone help with this. Thanx Cheers:)
Answer by JeyP4 · Jun 05, 2018 at 11:41 AM
I find below code working for raycasting direction :)
Vector3 u = new Vector3 (-Mathf.Tan (B * Mathf.Deg2Rad), Mathf.Tan (A * Mathf.Deg2Rad), 1);
u= Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z) * u;
But anyways many thanx for considering my question to answer.
For anyone looking at this question in future, I'm pretty sure the use of the Tan function here is incorrect and should have been using Sin ins$$anonymous$$d.
The reason I say that is because my interpretation of the information we have here is we know:
The angle
The length of the hypotenuse (the longest side) which is the length of whatever vector we are rotating, in this case it's
1
And we want to find, the length of the side opposite
the angle. The remaining side of the triangle is usually called the adjacent
.
Since we have that Tan(angle) = opposite / adjacent
I don't think we can use it, as we don't know the adjacent side length.
Ins$$anonymous$$d we can use Sin(angle) = opposite / hypotenuse
since here the hypotenuse
is always going to be of length 1, this is the same as Sin(angle) = opposite
.
I think the arguments are also in the wrong order based on the image, as the angle A
should relate to the x-axis and angle B
to the y-axis.
The final answer for most users cases would look more like:
Vector3 u = transform.rotation * new Vector3 ($$anonymous$$athf.Sin(A * $$anonymous$$athf.Deg2Rad), $$anonymous$$athf.Sin(B * $$anonymous$$athf.Deg2Rad), 1);
I'm glad you found an answer that works for you JeyP4, just explaining for the next person!
Answer by Scribe · Jun 04, 2018 at 08:53 PM
The easiest way looks to be projecting the vector calculated from A onto the X axis and adding to the vector calculated for B (or the same technique the other way around)
Vector3 aVec = ...;
Vector3 bVec = ...;
Vector3.Project(aVec, transform.right)+bVec;
Your answer
Follow this Question
Related Questions
Determining if my target is standing upright 4 Answers
Copy Roll From one Gameobject to another Without other rotations effecting it 0 Answers
The direction my camera is rotating should indicate the direction my object facing 0 Answers
Need solution for rotation with player input of X, Y, Z 1 Answer