Jump to content

Recommended Posts

Posted

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?

Let's build cool stuff and have fun. :)

Posted

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).

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...