Hello:
I have a unit vector in 3D space whose direction I wish to perturb by some angle within the range 0 to theta, with the position of the vector remaining the same. What is a way I can accomplish this?
Thanks.
EDIT: After thinking about the way I posed the question, it seems to be a bit too general. I'll attempt to make it more specific: Assume that the vector originates from the surface of an object (i.e. sphere, circle, box, line, cylinder, cone). If there are different methods to finding the new direction for each of those objects, then providing help for the sphere one is fine.
EDIT 2: I was going to type this in a comment but it was too much.
So I have orig_vector
, which I wish to perturb in some direction between 0 and theta
. The theta
can be thought of as forming a cone around my vector (with theta
being the angle between the center and one side of the cone) and I wish to generate a new vector within that cone. I can generate a point lying on the plane that is tangent to my vector and thus creating a unit vector in the direction of the point, call it rand_vector
. At this time, I orig_vector
and trand_vector
are two unit vectors perpendicular to each other.
I generate my first angle, angle1
between 0 and 2pi and I rotate rand_vector
around orig_vector
by angle1
, forming rand_vector2
. I looked up a resource online and it said that the second angle, angle2
should be between 0 and sin(theta)
(where theta
is the original "cone" angle). Then I rotate rand_vector2
by acos(angle2)
around the vector defined by the cross product between rand_vector2
and orig_vector
.
When I do this, I don't obtain the desired results. That is, when theta=0
, I still get perturbed vectors, and I expect to get orig_vector
. If anyone can explain the reason for the angles and why they are the way they are, I would greatly appreciate it.
EDIT 3: This is the final edit, I promise =). So I fixed my bug and everything that I described above works (it was an implementation bug, not a theory bug). However, my question about the angles (i.e. why is angle2 = sin(theta)*rand()
and why is perturbed_vector = rand_vector2.Rotate(rand_vector2.Cross(orig_vector), acos(angle2))
. Thanks so much!