- Home /
How to get a weighted random Vector2 between 3 points
I need to find a way to pick a random location between 3 points. If we are using the image below as an example I also need it to more likely pick a point at the base of the triangle. Does anyone know a method to do this?
untitled.png
(3.1 kB)
Comment
Answer by IgorAherne · Oct 23, 2016 at 05:19 PM
System.Random rnd = new System.Random();
float r_for_top = (float)rnd.Next( 0, 20) / 100.0f; //0-to-20
float r_for_left = (float)rnd.Next(0,100) / 100.0f; //0-to-100
float r_for_right = (float)rnd.Next(0,100) / 100;
Vector3 rnd_coord = (top_coord *r_for_top + left_coord* r_for_left + right_coord* r_for_right ) / 3;
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Find Vector3 perpendicular to Vector3 A in direction of Vector3 B 1 Answer
How would you fake air resistance? (c#) 2 Answers
Multiple Cars not working 1 Answer