Thread: Math Quiz 9
View Single Post
  #58   Spotlight this post!  
Unread 19-07-2016, 14:05
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,636
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Math Quiz 9

Quote:
Originally Posted by Caleb Sykes View Post
Given, you do need to generate at least 3 random numbers for this process, so if generating random numbers is resource intensive you may want to look for other methods.
You can do this with two random numbers by noticing that those right triangles get pretty skinny. Essentially, take the regular N-gon apart into those right isosceles triangles, and re-arrange them into a rectangle. In the large N limit, this rectangle will only be pi times as wide as it is tall.

Procedurally, calculate W = floor(r1/N); this tells you which wedge you are in (0 to N-1), then use r1 - W/N and r2 to determine where in that wedge as suggested above.

To do this (or Caleb's original suggestion) efficiently, you may want to pre-calculate a trig table of appropriate size.

Edit - and thanks, Caleb! I was thinking about attacking the same problem with the unit circle next, and I just realized I can adapt this technique to randomly pick r and theta with a uniform spatial distribution.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.

Last edited by GeeTwo : 19-07-2016 at 14:25.
Reply With Quote