Josh Posted February 16, 2010 Share Posted February 16, 2010 I have a vector in space. I want to make a ring of vectors that are offset from the original by a certain angle, so that they form a cone shape. I realize this can have multiple solutions. That's okay, as long as the resulting vectors form a cone around the original. How can this be done? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
TylerH Posted February 17, 2010 Share Posted February 17, 2010 In 2D: angle *= rand() * 6.28; // Pi*2, rand() should be a float between 0 and 1 float cosa = cos(angle); float sina = sin(angle); return vec2(cosa * x - sina * y, sina * x + cosa * y); In 3D: (up should be the local up vector, or a vector perpendicular to the vector you are testing against) // Rotate up vector by random amount around this Quaternion q; q.FromAngleAxis( rand() * 6.28, v ); up = q * up; // Finally rotate this by given angle around randomised up q.FromAngleAxis( angle, newUp ); return vec2(q * v); (Slightly modified from OGRE) NOTE: The above will give you deviant vectors that are offset by the angle, you can place some simple limits on the 0-1 random value to make it a cone shape, and then iterate a step function over however many segments of the cone you want to have (64 super precise, or 8 not so much). Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.