Shortest algorithm to determine sub-triangle

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











up vote
0
down vote

favorite












Fun (?) question here. Given an arbitrary point on the triangle pictured below, what is the "best" way to determine which of the 60 sub triangles it lies within? Suppose I have the coordinates for all sub-triangle vertices.



"Best" is from a programming POV, so my though is to just check if the point is above, below (or on), a given line... then repeat. So maybe you check if it's above or below the 2nd steepest of the 4 lines that intersect at the bottom left vertex - if it's above, check above/below line x, if it's below check above/below line y, etc.



With minimal thought put into the algorithm, I was able to determine the location in 7 steps (meaning above/below 7 different lines) for 16 of the sub-triangles, 6 steps for 32 of the sub-triangles, and 5 steps for 12 of the sub-triangles. I'm fairly certain that this is not optimal. When I say optimal, I'd really like to minimize the max, so the 7 step triangles bug me.



I think 6 steps for 56 of the triangles and 5 steps for 4 of the triangles is a lower bound on the length of the "optimal" solution, but I don't think is achievable.



Any thoughts at the optimal solution? My gut said to split the sub triangles as closely to evenly as possible in each step, but I'm not even sure that's true (or how to do that).



In case it helps, you can view the big triangle as 15 medium sized triangles (3 in each of the 3 corners, 6 in the middle). Each of those 15 medium sized triangles is subdivided into 4 small triangles.



Thanks!



The Triangle







share|cite|improve this question















  • 1




    Try posting this on Code Golf SE. Mathematics SE doesn't really provide 'algorithms' which you ask for.
    – Shawn Li
    Aug 1 at 20:53











  • I will, and thanks for the advice. However, I think the crux of the problem is mathematical in nature as I'm looking to exploit the symmetries of this triangle.
    – Brian
    Aug 1 at 21:05






  • 2




    It seems move like stack overflow or computerscience SE than code golf to me. Code golf is about writing programs in the fewest possible number of bits.
    – saulspatz
    Aug 1 at 21:28











  • My guess is that the answer depends on how the triangles are constructed. Do you have that information? Or is it just some random partition into 60 triangles?
    – Andrei
    Aug 1 at 23:04






  • 2




    @ShawnLi Please do not suggest users to go to any site you're unfamiliar of. We only allow programming challenge on our site, with some exceptions. Question about constructing an algorithm is not one of them.
    – user202729
    Aug 2 at 0:52














up vote
0
down vote

favorite












Fun (?) question here. Given an arbitrary point on the triangle pictured below, what is the "best" way to determine which of the 60 sub triangles it lies within? Suppose I have the coordinates for all sub-triangle vertices.



"Best" is from a programming POV, so my though is to just check if the point is above, below (or on), a given line... then repeat. So maybe you check if it's above or below the 2nd steepest of the 4 lines that intersect at the bottom left vertex - if it's above, check above/below line x, if it's below check above/below line y, etc.



With minimal thought put into the algorithm, I was able to determine the location in 7 steps (meaning above/below 7 different lines) for 16 of the sub-triangles, 6 steps for 32 of the sub-triangles, and 5 steps for 12 of the sub-triangles. I'm fairly certain that this is not optimal. When I say optimal, I'd really like to minimize the max, so the 7 step triangles bug me.



I think 6 steps for 56 of the triangles and 5 steps for 4 of the triangles is a lower bound on the length of the "optimal" solution, but I don't think is achievable.



Any thoughts at the optimal solution? My gut said to split the sub triangles as closely to evenly as possible in each step, but I'm not even sure that's true (or how to do that).



In case it helps, you can view the big triangle as 15 medium sized triangles (3 in each of the 3 corners, 6 in the middle). Each of those 15 medium sized triangles is subdivided into 4 small triangles.



Thanks!



The Triangle







share|cite|improve this question















  • 1




    Try posting this on Code Golf SE. Mathematics SE doesn't really provide 'algorithms' which you ask for.
    – Shawn Li
    Aug 1 at 20:53











  • I will, and thanks for the advice. However, I think the crux of the problem is mathematical in nature as I'm looking to exploit the symmetries of this triangle.
    – Brian
    Aug 1 at 21:05






  • 2




    It seems move like stack overflow or computerscience SE than code golf to me. Code golf is about writing programs in the fewest possible number of bits.
    – saulspatz
    Aug 1 at 21:28











  • My guess is that the answer depends on how the triangles are constructed. Do you have that information? Or is it just some random partition into 60 triangles?
    – Andrei
    Aug 1 at 23:04






  • 2




    @ShawnLi Please do not suggest users to go to any site you're unfamiliar of. We only allow programming challenge on our site, with some exceptions. Question about constructing an algorithm is not one of them.
    – user202729
    Aug 2 at 0:52












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Fun (?) question here. Given an arbitrary point on the triangle pictured below, what is the "best" way to determine which of the 60 sub triangles it lies within? Suppose I have the coordinates for all sub-triangle vertices.



"Best" is from a programming POV, so my though is to just check if the point is above, below (or on), a given line... then repeat. So maybe you check if it's above or below the 2nd steepest of the 4 lines that intersect at the bottom left vertex - if it's above, check above/below line x, if it's below check above/below line y, etc.



With minimal thought put into the algorithm, I was able to determine the location in 7 steps (meaning above/below 7 different lines) for 16 of the sub-triangles, 6 steps for 32 of the sub-triangles, and 5 steps for 12 of the sub-triangles. I'm fairly certain that this is not optimal. When I say optimal, I'd really like to minimize the max, so the 7 step triangles bug me.



I think 6 steps for 56 of the triangles and 5 steps for 4 of the triangles is a lower bound on the length of the "optimal" solution, but I don't think is achievable.



Any thoughts at the optimal solution? My gut said to split the sub triangles as closely to evenly as possible in each step, but I'm not even sure that's true (or how to do that).



In case it helps, you can view the big triangle as 15 medium sized triangles (3 in each of the 3 corners, 6 in the middle). Each of those 15 medium sized triangles is subdivided into 4 small triangles.



Thanks!



The Triangle







share|cite|improve this question











Fun (?) question here. Given an arbitrary point on the triangle pictured below, what is the "best" way to determine which of the 60 sub triangles it lies within? Suppose I have the coordinates for all sub-triangle vertices.



"Best" is from a programming POV, so my though is to just check if the point is above, below (or on), a given line... then repeat. So maybe you check if it's above or below the 2nd steepest of the 4 lines that intersect at the bottom left vertex - if it's above, check above/below line x, if it's below check above/below line y, etc.



With minimal thought put into the algorithm, I was able to determine the location in 7 steps (meaning above/below 7 different lines) for 16 of the sub-triangles, 6 steps for 32 of the sub-triangles, and 5 steps for 12 of the sub-triangles. I'm fairly certain that this is not optimal. When I say optimal, I'd really like to minimize the max, so the 7 step triangles bug me.



I think 6 steps for 56 of the triangles and 5 steps for 4 of the triangles is a lower bound on the length of the "optimal" solution, but I don't think is achievable.



Any thoughts at the optimal solution? My gut said to split the sub triangles as closely to evenly as possible in each step, but I'm not even sure that's true (or how to do that).



In case it helps, you can view the big triangle as 15 medium sized triangles (3 in each of the 3 corners, 6 in the middle). Each of those 15 medium sized triangles is subdivided into 4 small triangles.



Thanks!



The Triangle









share|cite|improve this question










share|cite|improve this question




share|cite|improve this question









asked Aug 1 at 20:51









Brian

287




287







  • 1




    Try posting this on Code Golf SE. Mathematics SE doesn't really provide 'algorithms' which you ask for.
    – Shawn Li
    Aug 1 at 20:53











  • I will, and thanks for the advice. However, I think the crux of the problem is mathematical in nature as I'm looking to exploit the symmetries of this triangle.
    – Brian
    Aug 1 at 21:05






  • 2




    It seems move like stack overflow or computerscience SE than code golf to me. Code golf is about writing programs in the fewest possible number of bits.
    – saulspatz
    Aug 1 at 21:28











  • My guess is that the answer depends on how the triangles are constructed. Do you have that information? Or is it just some random partition into 60 triangles?
    – Andrei
    Aug 1 at 23:04






  • 2




    @ShawnLi Please do not suggest users to go to any site you're unfamiliar of. We only allow programming challenge on our site, with some exceptions. Question about constructing an algorithm is not one of them.
    – user202729
    Aug 2 at 0:52












  • 1




    Try posting this on Code Golf SE. Mathematics SE doesn't really provide 'algorithms' which you ask for.
    – Shawn Li
    Aug 1 at 20:53











  • I will, and thanks for the advice. However, I think the crux of the problem is mathematical in nature as I'm looking to exploit the symmetries of this triangle.
    – Brian
    Aug 1 at 21:05






  • 2




    It seems move like stack overflow or computerscience SE than code golf to me. Code golf is about writing programs in the fewest possible number of bits.
    – saulspatz
    Aug 1 at 21:28











  • My guess is that the answer depends on how the triangles are constructed. Do you have that information? Or is it just some random partition into 60 triangles?
    – Andrei
    Aug 1 at 23:04






  • 2




    @ShawnLi Please do not suggest users to go to any site you're unfamiliar of. We only allow programming challenge on our site, with some exceptions. Question about constructing an algorithm is not one of them.
    – user202729
    Aug 2 at 0:52







1




1




Try posting this on Code Golf SE. Mathematics SE doesn't really provide 'algorithms' which you ask for.
– Shawn Li
Aug 1 at 20:53





Try posting this on Code Golf SE. Mathematics SE doesn't really provide 'algorithms' which you ask for.
– Shawn Li
Aug 1 at 20:53













I will, and thanks for the advice. However, I think the crux of the problem is mathematical in nature as I'm looking to exploit the symmetries of this triangle.
– Brian
Aug 1 at 21:05




I will, and thanks for the advice. However, I think the crux of the problem is mathematical in nature as I'm looking to exploit the symmetries of this triangle.
– Brian
Aug 1 at 21:05




2




2




It seems move like stack overflow or computerscience SE than code golf to me. Code golf is about writing programs in the fewest possible number of bits.
– saulspatz
Aug 1 at 21:28





It seems move like stack overflow or computerscience SE than code golf to me. Code golf is about writing programs in the fewest possible number of bits.
– saulspatz
Aug 1 at 21:28













My guess is that the answer depends on how the triangles are constructed. Do you have that information? Or is it just some random partition into 60 triangles?
– Andrei
Aug 1 at 23:04




My guess is that the answer depends on how the triangles are constructed. Do you have that information? Or is it just some random partition into 60 triangles?
– Andrei
Aug 1 at 23:04




2




2




@ShawnLi Please do not suggest users to go to any site you're unfamiliar of. We only allow programming challenge on our site, with some exceptions. Question about constructing an algorithm is not one of them.
– user202729
Aug 2 at 0:52




@ShawnLi Please do not suggest users to go to any site you're unfamiliar of. We only allow programming challenge on our site, with some exceptions. Question about constructing an algorithm is not one of them.
– user202729
Aug 2 at 0:52















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%2f2869507%2fshortest-algorithm-to-determine-sub-triangle%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%2f2869507%2fshortest-algorithm-to-determine-sub-triangle%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What is the equation of a 3D cone with generalised tilt?

Color the edges and diagonals of a regular polygon

Relationship between determinant of matrix and determinant of adjoint?