Random point within triangle + within 2 radiuses

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I am working on pathfinding for a 2D game, and need to obtain a random point within a triangle. This is simple, I am just sampling 3 times from a uniformly distributed random variable, then blend the 3 coordinates to get my random point.



given 3 triangle coordinates (2D): $A$, $B$, $C$ I can get a random point like this: uniform random point in triangle



However, now I also have a constrain that my random point must be between minRadius and maxRadius from some external coordinate.



The triangle is guaranteed to have some or all of its area inside this range.
There are seven possible states:



enter image description here



Is there a simple way to get such a random coordinate? Clamping it to the circumference (if outside of the range) would be undesirable, as it would introduce a bias towards the circumferences



Edit:



Both radiuses are measured from the same coordinate







share|cite|improve this question






















  • Could you be more specific how you choose points in the triangles?
    – M. Nestor
    Aug 17 at 23:07










  • I've edited my question, I am using this post's method: math.stackexchange.com/q/18686/147567
    – Kari
    Aug 17 at 23:13







  • 2




    By far, the easiest approach is to use the rejection method. Basically, you repeat the following process. Take a random point inside the triangle like you are currently doing, accept it is if it satisfies your other constraint, and reject it if it does not. Stop after you accept a point. The only downside to this method is that if you have a very small overlap between the annulus (your other constraint) and the triangle, then it may slow down your game. But I doubt that this will be an actual bottleneck in your code.
    – sasquires
    Aug 17 at 23:29















up vote
0
down vote

favorite












I am working on pathfinding for a 2D game, and need to obtain a random point within a triangle. This is simple, I am just sampling 3 times from a uniformly distributed random variable, then blend the 3 coordinates to get my random point.



given 3 triangle coordinates (2D): $A$, $B$, $C$ I can get a random point like this: uniform random point in triangle



However, now I also have a constrain that my random point must be between minRadius and maxRadius from some external coordinate.



The triangle is guaranteed to have some or all of its area inside this range.
There are seven possible states:



enter image description here



Is there a simple way to get such a random coordinate? Clamping it to the circumference (if outside of the range) would be undesirable, as it would introduce a bias towards the circumferences



Edit:



Both radiuses are measured from the same coordinate







share|cite|improve this question






















  • Could you be more specific how you choose points in the triangles?
    – M. Nestor
    Aug 17 at 23:07










  • I've edited my question, I am using this post's method: math.stackexchange.com/q/18686/147567
    – Kari
    Aug 17 at 23:13







  • 2




    By far, the easiest approach is to use the rejection method. Basically, you repeat the following process. Take a random point inside the triangle like you are currently doing, accept it is if it satisfies your other constraint, and reject it if it does not. Stop after you accept a point. The only downside to this method is that if you have a very small overlap between the annulus (your other constraint) and the triangle, then it may slow down your game. But I doubt that this will be an actual bottleneck in your code.
    – sasquires
    Aug 17 at 23:29













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am working on pathfinding for a 2D game, and need to obtain a random point within a triangle. This is simple, I am just sampling 3 times from a uniformly distributed random variable, then blend the 3 coordinates to get my random point.



given 3 triangle coordinates (2D): $A$, $B$, $C$ I can get a random point like this: uniform random point in triangle



However, now I also have a constrain that my random point must be between minRadius and maxRadius from some external coordinate.



The triangle is guaranteed to have some or all of its area inside this range.
There are seven possible states:



enter image description here



Is there a simple way to get such a random coordinate? Clamping it to the circumference (if outside of the range) would be undesirable, as it would introduce a bias towards the circumferences



Edit:



Both radiuses are measured from the same coordinate







share|cite|improve this question














I am working on pathfinding for a 2D game, and need to obtain a random point within a triangle. This is simple, I am just sampling 3 times from a uniformly distributed random variable, then blend the 3 coordinates to get my random point.



given 3 triangle coordinates (2D): $A$, $B$, $C$ I can get a random point like this: uniform random point in triangle



However, now I also have a constrain that my random point must be between minRadius and maxRadius from some external coordinate.



The triangle is guaranteed to have some or all of its area inside this range.
There are seven possible states:



enter image description here



Is there a simple way to get such a random coordinate? Clamping it to the circumference (if outside of the range) would be undesirable, as it would introduce a bias towards the circumferences



Edit:



Both radiuses are measured from the same coordinate









share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Aug 17 at 23:12

























asked Aug 17 at 22:35









Kari

1479




1479











  • Could you be more specific how you choose points in the triangles?
    – M. Nestor
    Aug 17 at 23:07










  • I've edited my question, I am using this post's method: math.stackexchange.com/q/18686/147567
    – Kari
    Aug 17 at 23:13







  • 2




    By far, the easiest approach is to use the rejection method. Basically, you repeat the following process. Take a random point inside the triangle like you are currently doing, accept it is if it satisfies your other constraint, and reject it if it does not. Stop after you accept a point. The only downside to this method is that if you have a very small overlap between the annulus (your other constraint) and the triangle, then it may slow down your game. But I doubt that this will be an actual bottleneck in your code.
    – sasquires
    Aug 17 at 23:29

















  • Could you be more specific how you choose points in the triangles?
    – M. Nestor
    Aug 17 at 23:07










  • I've edited my question, I am using this post's method: math.stackexchange.com/q/18686/147567
    – Kari
    Aug 17 at 23:13







  • 2




    By far, the easiest approach is to use the rejection method. Basically, you repeat the following process. Take a random point inside the triangle like you are currently doing, accept it is if it satisfies your other constraint, and reject it if it does not. Stop after you accept a point. The only downside to this method is that if you have a very small overlap between the annulus (your other constraint) and the triangle, then it may slow down your game. But I doubt that this will be an actual bottleneck in your code.
    – sasquires
    Aug 17 at 23:29
















Could you be more specific how you choose points in the triangles?
– M. Nestor
Aug 17 at 23:07




Could you be more specific how you choose points in the triangles?
– M. Nestor
Aug 17 at 23:07












I've edited my question, I am using this post's method: math.stackexchange.com/q/18686/147567
– Kari
Aug 17 at 23:13





I've edited my question, I am using this post's method: math.stackexchange.com/q/18686/147567
– Kari
Aug 17 at 23:13





2




2




By far, the easiest approach is to use the rejection method. Basically, you repeat the following process. Take a random point inside the triangle like you are currently doing, accept it is if it satisfies your other constraint, and reject it if it does not. Stop after you accept a point. The only downside to this method is that if you have a very small overlap between the annulus (your other constraint) and the triangle, then it may slow down your game. But I doubt that this will be an actual bottleneck in your code.
– sasquires
Aug 17 at 23:29





By far, the easiest approach is to use the rejection method. Basically, you repeat the following process. Take a random point inside the triangle like you are currently doing, accept it is if it satisfies your other constraint, and reject it if it does not. Stop after you accept a point. The only downside to this method is that if you have a very small overlap between the annulus (your other constraint) and the triangle, then it may slow down your game. But I doubt that this will be an actual bottleneck in your code.
– sasquires
Aug 17 at 23:29
















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "69"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2886256%2frandom-point-within-triangle-within-2-radiuses%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2886256%2frandom-point-within-triangle-within-2-radiuses%23new-answer', 'question_page');

);

Post as a guest













































































這個網誌中的熱門文章

tkz-euclide: tkzDrawCircle[R] not working

How to combine Bézier curves to a surface?

1st Magritte Awards