Algorithm to find if a triangle (with given vertices) contains a point $P$
$begingroup$
I came up with the following algorithm to find weather a given triangle contains origin or not. Applying on $1000$ test cases, I got $232$ while the correct answer is $228$. Please verify if the algorithm is mathematically valid or not.
$1$)Name the vertices $A,B,C$
$2$)Find Angle of line from origin to the point with positive $x$-Axis. Name them $angle a,angle b, angle c$. This is done via $arctan(left|{yover x}right|)$.
If First quadrent, no change required.
If second quadrent, $180-arctan(left|{yover x}right|)$.
If third quadrent $270-arctan(left|{yover x}right|)$.
If fourth, then $360-arctan(left|{yover x}right|)$
$3$)Find Angle between the lines $OA,OB,OC$.
which would be min$left(|angle a-angle b|,360-|angle a-angle b|right)$ for $OA$ and $OB$ and so on.
$4$) If the sum of these differences is $360$, then the triangle contains origin.
The test cases do NOT contain any point on origin or the $x$ or $y$ axis.
trigonometry proof-verification
$endgroup$
|
show 1 more comment
$begingroup$
I came up with the following algorithm to find weather a given triangle contains origin or not. Applying on $1000$ test cases, I got $232$ while the correct answer is $228$. Please verify if the algorithm is mathematically valid or not.
$1$)Name the vertices $A,B,C$
$2$)Find Angle of line from origin to the point with positive $x$-Axis. Name them $angle a,angle b, angle c$. This is done via $arctan(left|{yover x}right|)$.
If First quadrent, no change required.
If second quadrent, $180-arctan(left|{yover x}right|)$.
If third quadrent $270-arctan(left|{yover x}right|)$.
If fourth, then $360-arctan(left|{yover x}right|)$
$3$)Find Angle between the lines $OA,OB,OC$.
which would be min$left(|angle a-angle b|,360-|angle a-angle b|right)$ for $OA$ and $OB$ and so on.
$4$) If the sum of these differences is $360$, then the triangle contains origin.
The test cases do NOT contain any point on origin or the $x$ or $y$ axis.
trigonometry proof-verification
$endgroup$
$begingroup$
You answered your own question. It is obviously not correct since $232 ne 228$.
$endgroup$
– gammatester
Dec 17 '18 at 10:38
$begingroup$
@gammatester What is the error in the algorithm then?
$endgroup$
– Anvit
Dec 17 '18 at 10:40
$begingroup$
I do not know, but it is rather obscure. I suggest you have a close look at the test cases that were wrong.
$endgroup$
– gammatester
Dec 17 '18 at 10:49
$begingroup$
@gammatester. Thats the problem. I dont know which test cases are wrong. Is these some other method to verify?
$endgroup$
– Anvit
Dec 17 '18 at 10:51
$begingroup$
Huh? How do you know that they are wrong? If you search an algorithm look e.g. at mochima.com/articles/cuj_geometry_article/… and cs.cmu.edu/~quake/robust.html
$endgroup$
– gammatester
Dec 17 '18 at 10:56
|
show 1 more comment
$begingroup$
I came up with the following algorithm to find weather a given triangle contains origin or not. Applying on $1000$ test cases, I got $232$ while the correct answer is $228$. Please verify if the algorithm is mathematically valid or not.
$1$)Name the vertices $A,B,C$
$2$)Find Angle of line from origin to the point with positive $x$-Axis. Name them $angle a,angle b, angle c$. This is done via $arctan(left|{yover x}right|)$.
If First quadrent, no change required.
If second quadrent, $180-arctan(left|{yover x}right|)$.
If third quadrent $270-arctan(left|{yover x}right|)$.
If fourth, then $360-arctan(left|{yover x}right|)$
$3$)Find Angle between the lines $OA,OB,OC$.
which would be min$left(|angle a-angle b|,360-|angle a-angle b|right)$ for $OA$ and $OB$ and so on.
$4$) If the sum of these differences is $360$, then the triangle contains origin.
The test cases do NOT contain any point on origin or the $x$ or $y$ axis.
trigonometry proof-verification
$endgroup$
I came up with the following algorithm to find weather a given triangle contains origin or not. Applying on $1000$ test cases, I got $232$ while the correct answer is $228$. Please verify if the algorithm is mathematically valid or not.
$1$)Name the vertices $A,B,C$
$2$)Find Angle of line from origin to the point with positive $x$-Axis. Name them $angle a,angle b, angle c$. This is done via $arctan(left|{yover x}right|)$.
If First quadrent, no change required.
If second quadrent, $180-arctan(left|{yover x}right|)$.
If third quadrent $270-arctan(left|{yover x}right|)$.
If fourth, then $360-arctan(left|{yover x}right|)$
$3$)Find Angle between the lines $OA,OB,OC$.
which would be min$left(|angle a-angle b|,360-|angle a-angle b|right)$ for $OA$ and $OB$ and so on.
$4$) If the sum of these differences is $360$, then the triangle contains origin.
The test cases do NOT contain any point on origin or the $x$ or $y$ axis.
trigonometry proof-verification
trigonometry proof-verification
edited Dec 17 '18 at 10:41
PM.
3,3532925
3,3532925
asked Dec 17 '18 at 10:27
AnvitAnvit
1,734419
1,734419
$begingroup$
You answered your own question. It is obviously not correct since $232 ne 228$.
$endgroup$
– gammatester
Dec 17 '18 at 10:38
$begingroup$
@gammatester What is the error in the algorithm then?
$endgroup$
– Anvit
Dec 17 '18 at 10:40
$begingroup$
I do not know, but it is rather obscure. I suggest you have a close look at the test cases that were wrong.
$endgroup$
– gammatester
Dec 17 '18 at 10:49
$begingroup$
@gammatester. Thats the problem. I dont know which test cases are wrong. Is these some other method to verify?
$endgroup$
– Anvit
Dec 17 '18 at 10:51
$begingroup$
Huh? How do you know that they are wrong? If you search an algorithm look e.g. at mochima.com/articles/cuj_geometry_article/… and cs.cmu.edu/~quake/robust.html
$endgroup$
– gammatester
Dec 17 '18 at 10:56
|
show 1 more comment
$begingroup$
You answered your own question. It is obviously not correct since $232 ne 228$.
$endgroup$
– gammatester
Dec 17 '18 at 10:38
$begingroup$
@gammatester What is the error in the algorithm then?
$endgroup$
– Anvit
Dec 17 '18 at 10:40
$begingroup$
I do not know, but it is rather obscure. I suggest you have a close look at the test cases that were wrong.
$endgroup$
– gammatester
Dec 17 '18 at 10:49
$begingroup$
@gammatester. Thats the problem. I dont know which test cases are wrong. Is these some other method to verify?
$endgroup$
– Anvit
Dec 17 '18 at 10:51
$begingroup$
Huh? How do you know that they are wrong? If you search an algorithm look e.g. at mochima.com/articles/cuj_geometry_article/… and cs.cmu.edu/~quake/robust.html
$endgroup$
– gammatester
Dec 17 '18 at 10:56
$begingroup$
You answered your own question. It is obviously not correct since $232 ne 228$.
$endgroup$
– gammatester
Dec 17 '18 at 10:38
$begingroup$
You answered your own question. It is obviously not correct since $232 ne 228$.
$endgroup$
– gammatester
Dec 17 '18 at 10:38
$begingroup$
@gammatester What is the error in the algorithm then?
$endgroup$
– Anvit
Dec 17 '18 at 10:40
$begingroup$
@gammatester What is the error in the algorithm then?
$endgroup$
– Anvit
Dec 17 '18 at 10:40
$begingroup$
I do not know, but it is rather obscure. I suggest you have a close look at the test cases that were wrong.
$endgroup$
– gammatester
Dec 17 '18 at 10:49
$begingroup$
I do not know, but it is rather obscure. I suggest you have a close look at the test cases that were wrong.
$endgroup$
– gammatester
Dec 17 '18 at 10:49
$begingroup$
@gammatester. Thats the problem. I dont know which test cases are wrong. Is these some other method to verify?
$endgroup$
– Anvit
Dec 17 '18 at 10:51
$begingroup$
@gammatester. Thats the problem. I dont know which test cases are wrong. Is these some other method to verify?
$endgroup$
– Anvit
Dec 17 '18 at 10:51
$begingroup$
Huh? How do you know that they are wrong? If you search an algorithm look e.g. at mochima.com/articles/cuj_geometry_article/… and cs.cmu.edu/~quake/robust.html
$endgroup$
– gammatester
Dec 17 '18 at 10:56
$begingroup$
Huh? How do you know that they are wrong? If you search an algorithm look e.g. at mochima.com/articles/cuj_geometry_article/… and cs.cmu.edu/~quake/robust.html
$endgroup$
– gammatester
Dec 17 '18 at 10:56
|
show 1 more comment
3 Answers
3
active
oldest
votes
$begingroup$
Your method is totally inefficient and involves $arctan$ function which is expensive from the computation point of view.
It's better to check angle orientations:
If the origin is in the triangle, angles $angle AOB$, $angle BOC$, $angle COA$ have the same orientation.
If the origin is outside of the triangle, angles $angle AOB$, $angle BOC$, $angle COA$ do not have the same orientation.
Angle orientation between vectors is reflected in the cross product. In this particular case:
$$vec{OA}timesvec{OB}=(x_Ay_B-x_By_A)vec k$$
$$vec{OB}timesvec{OC}=(x_By_C-x_Cy_B)vec k$$
$$vec{OC}timesvec{OA}=(x_Cy_A-x_Ay_C)vec k$$
If the value between brackets is positive, the cross product is pointing upwards and the angle has counterclockwise orientation. It's exactly the opposite if the value in brackets is negative.
The algorithm would look like this:
1) Calclulate the following values:
$$z_1=x_Ay_B-x_By_A$$
$$z_2=x_By_C-x_Cy_B$$
$$z_3=x_Cy_A-x_Ay_C$$
2) If $z_1=0$ or $z_2=0$ or $z_3=0$, the origin lies on some triangle edge
3) If $z_1,z_2,z_3$ are all of the same sign, the origin is inside the triangle, outside of it otherwise.
You can probably fix your method and force it to work, but it's still too complicated, totally inefficient and hard to follow.
Also functions like $arctan$ are for mathematicians. If you have to compute the value of it in your computer code, you should use something like atan2(). That function takes two arguments ($x$ and $y$ values) and takes care of the quadrant in question.
$endgroup$
$begingroup$
There is obviously something very wrong with my method. I think It was by chance my answer was so close. I extracted the test cases containing origin (with your alogorith) and compared them with mine. Here are 2(out of 60) of the coordinates rejected by my algorithm but accepted by yours $(244, -276, 713, 330, -897, -214),(-105, 918, 188, 237, -110, -591)$ and two accepted by mine but rejected by yours $(-226, -790, 28, -930, 827, 783),(-608, -273, -141, 930, 687, 380)$
$endgroup$
– Anvit
Dec 17 '18 at 11:51
add a comment |
$begingroup$
you might like to try an alternative method that may be more transparent and robust.
supposing Q lies within ABC. a test probe P moving from A towards B should initially observe a decrease in the distance $PQ = r_{lambda}$. if we parameterize the position of the probe as
$$
P_{lambda} = lambda A + (1-lambda) B
$$
then for an internal point $Q$ we should have:
$$
frac{d|P_lambda Q|^2}{dlambda}bigg|_{lambda= 0} lt 0
$$
if $A = (x_1,y_1), B= (x_2, y_2), C=(x_3,y_3)$, and $Q=(x_0, y_0)$ then this test computes as:
$$
(a_2-a_1)(a_1-a_0) +(b_2-b_1)(b_1-b_0) lt 0
$$
with similar tests for the other two sides, BC and CA, obtained by cyclic permutation.
$endgroup$
add a comment |
$begingroup$
If the point is in the $3^{rd}$ quadrant, the angle it makes with the $x$ axis in the anti-clockwise direction is $180+arctan(Big|frac yxBig|)$
$endgroup$
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3043778%2falgorithm-to-find-if-a-triangle-with-given-vertices-contains-a-point-p%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Your method is totally inefficient and involves $arctan$ function which is expensive from the computation point of view.
It's better to check angle orientations:
If the origin is in the triangle, angles $angle AOB$, $angle BOC$, $angle COA$ have the same orientation.
If the origin is outside of the triangle, angles $angle AOB$, $angle BOC$, $angle COA$ do not have the same orientation.
Angle orientation between vectors is reflected in the cross product. In this particular case:
$$vec{OA}timesvec{OB}=(x_Ay_B-x_By_A)vec k$$
$$vec{OB}timesvec{OC}=(x_By_C-x_Cy_B)vec k$$
$$vec{OC}timesvec{OA}=(x_Cy_A-x_Ay_C)vec k$$
If the value between brackets is positive, the cross product is pointing upwards and the angle has counterclockwise orientation. It's exactly the opposite if the value in brackets is negative.
The algorithm would look like this:
1) Calclulate the following values:
$$z_1=x_Ay_B-x_By_A$$
$$z_2=x_By_C-x_Cy_B$$
$$z_3=x_Cy_A-x_Ay_C$$
2) If $z_1=0$ or $z_2=0$ or $z_3=0$, the origin lies on some triangle edge
3) If $z_1,z_2,z_3$ are all of the same sign, the origin is inside the triangle, outside of it otherwise.
You can probably fix your method and force it to work, but it's still too complicated, totally inefficient and hard to follow.
Also functions like $arctan$ are for mathematicians. If you have to compute the value of it in your computer code, you should use something like atan2(). That function takes two arguments ($x$ and $y$ values) and takes care of the quadrant in question.
$endgroup$
$begingroup$
There is obviously something very wrong with my method. I think It was by chance my answer was so close. I extracted the test cases containing origin (with your alogorith) and compared them with mine. Here are 2(out of 60) of the coordinates rejected by my algorithm but accepted by yours $(244, -276, 713, 330, -897, -214),(-105, 918, 188, 237, -110, -591)$ and two accepted by mine but rejected by yours $(-226, -790, 28, -930, 827, 783),(-608, -273, -141, 930, 687, 380)$
$endgroup$
– Anvit
Dec 17 '18 at 11:51
add a comment |
$begingroup$
Your method is totally inefficient and involves $arctan$ function which is expensive from the computation point of view.
It's better to check angle orientations:
If the origin is in the triangle, angles $angle AOB$, $angle BOC$, $angle COA$ have the same orientation.
If the origin is outside of the triangle, angles $angle AOB$, $angle BOC$, $angle COA$ do not have the same orientation.
Angle orientation between vectors is reflected in the cross product. In this particular case:
$$vec{OA}timesvec{OB}=(x_Ay_B-x_By_A)vec k$$
$$vec{OB}timesvec{OC}=(x_By_C-x_Cy_B)vec k$$
$$vec{OC}timesvec{OA}=(x_Cy_A-x_Ay_C)vec k$$
If the value between brackets is positive, the cross product is pointing upwards and the angle has counterclockwise orientation. It's exactly the opposite if the value in brackets is negative.
The algorithm would look like this:
1) Calclulate the following values:
$$z_1=x_Ay_B-x_By_A$$
$$z_2=x_By_C-x_Cy_B$$
$$z_3=x_Cy_A-x_Ay_C$$
2) If $z_1=0$ or $z_2=0$ or $z_3=0$, the origin lies on some triangle edge
3) If $z_1,z_2,z_3$ are all of the same sign, the origin is inside the triangle, outside of it otherwise.
You can probably fix your method and force it to work, but it's still too complicated, totally inefficient and hard to follow.
Also functions like $arctan$ are for mathematicians. If you have to compute the value of it in your computer code, you should use something like atan2(). That function takes two arguments ($x$ and $y$ values) and takes care of the quadrant in question.
$endgroup$
$begingroup$
There is obviously something very wrong with my method. I think It was by chance my answer was so close. I extracted the test cases containing origin (with your alogorith) and compared them with mine. Here are 2(out of 60) of the coordinates rejected by my algorithm but accepted by yours $(244, -276, 713, 330, -897, -214),(-105, 918, 188, 237, -110, -591)$ and two accepted by mine but rejected by yours $(-226, -790, 28, -930, 827, 783),(-608, -273, -141, 930, 687, 380)$
$endgroup$
– Anvit
Dec 17 '18 at 11:51
add a comment |
$begingroup$
Your method is totally inefficient and involves $arctan$ function which is expensive from the computation point of view.
It's better to check angle orientations:
If the origin is in the triangle, angles $angle AOB$, $angle BOC$, $angle COA$ have the same orientation.
If the origin is outside of the triangle, angles $angle AOB$, $angle BOC$, $angle COA$ do not have the same orientation.
Angle orientation between vectors is reflected in the cross product. In this particular case:
$$vec{OA}timesvec{OB}=(x_Ay_B-x_By_A)vec k$$
$$vec{OB}timesvec{OC}=(x_By_C-x_Cy_B)vec k$$
$$vec{OC}timesvec{OA}=(x_Cy_A-x_Ay_C)vec k$$
If the value between brackets is positive, the cross product is pointing upwards and the angle has counterclockwise orientation. It's exactly the opposite if the value in brackets is negative.
The algorithm would look like this:
1) Calclulate the following values:
$$z_1=x_Ay_B-x_By_A$$
$$z_2=x_By_C-x_Cy_B$$
$$z_3=x_Cy_A-x_Ay_C$$
2) If $z_1=0$ or $z_2=0$ or $z_3=0$, the origin lies on some triangle edge
3) If $z_1,z_2,z_3$ are all of the same sign, the origin is inside the triangle, outside of it otherwise.
You can probably fix your method and force it to work, but it's still too complicated, totally inefficient and hard to follow.
Also functions like $arctan$ are for mathematicians. If you have to compute the value of it in your computer code, you should use something like atan2(). That function takes two arguments ($x$ and $y$ values) and takes care of the quadrant in question.
$endgroup$
Your method is totally inefficient and involves $arctan$ function which is expensive from the computation point of view.
It's better to check angle orientations:
If the origin is in the triangle, angles $angle AOB$, $angle BOC$, $angle COA$ have the same orientation.
If the origin is outside of the triangle, angles $angle AOB$, $angle BOC$, $angle COA$ do not have the same orientation.
Angle orientation between vectors is reflected in the cross product. In this particular case:
$$vec{OA}timesvec{OB}=(x_Ay_B-x_By_A)vec k$$
$$vec{OB}timesvec{OC}=(x_By_C-x_Cy_B)vec k$$
$$vec{OC}timesvec{OA}=(x_Cy_A-x_Ay_C)vec k$$
If the value between brackets is positive, the cross product is pointing upwards and the angle has counterclockwise orientation. It's exactly the opposite if the value in brackets is negative.
The algorithm would look like this:
1) Calclulate the following values:
$$z_1=x_Ay_B-x_By_A$$
$$z_2=x_By_C-x_Cy_B$$
$$z_3=x_Cy_A-x_Ay_C$$
2) If $z_1=0$ or $z_2=0$ or $z_3=0$, the origin lies on some triangle edge
3) If $z_1,z_2,z_3$ are all of the same sign, the origin is inside the triangle, outside of it otherwise.
You can probably fix your method and force it to work, but it's still too complicated, totally inefficient and hard to follow.
Also functions like $arctan$ are for mathematicians. If you have to compute the value of it in your computer code, you should use something like atan2(). That function takes two arguments ($x$ and $y$ values) and takes care of the quadrant in question.
edited Dec 17 '18 at 11:33
answered Dec 17 '18 at 11:27
OldboyOldboy
8,66211036
8,66211036
$begingroup$
There is obviously something very wrong with my method. I think It was by chance my answer was so close. I extracted the test cases containing origin (with your alogorith) and compared them with mine. Here are 2(out of 60) of the coordinates rejected by my algorithm but accepted by yours $(244, -276, 713, 330, -897, -214),(-105, 918, 188, 237, -110, -591)$ and two accepted by mine but rejected by yours $(-226, -790, 28, -930, 827, 783),(-608, -273, -141, 930, 687, 380)$
$endgroup$
– Anvit
Dec 17 '18 at 11:51
add a comment |
$begingroup$
There is obviously something very wrong with my method. I think It was by chance my answer was so close. I extracted the test cases containing origin (with your alogorith) and compared them with mine. Here are 2(out of 60) of the coordinates rejected by my algorithm but accepted by yours $(244, -276, 713, 330, -897, -214),(-105, 918, 188, 237, -110, -591)$ and two accepted by mine but rejected by yours $(-226, -790, 28, -930, 827, 783),(-608, -273, -141, 930, 687, 380)$
$endgroup$
– Anvit
Dec 17 '18 at 11:51
$begingroup$
There is obviously something very wrong with my method. I think It was by chance my answer was so close. I extracted the test cases containing origin (with your alogorith) and compared them with mine. Here are 2(out of 60) of the coordinates rejected by my algorithm but accepted by yours $(244, -276, 713, 330, -897, -214),(-105, 918, 188, 237, -110, -591)$ and two accepted by mine but rejected by yours $(-226, -790, 28, -930, 827, 783),(-608, -273, -141, 930, 687, 380)$
$endgroup$
– Anvit
Dec 17 '18 at 11:51
$begingroup$
There is obviously something very wrong with my method. I think It was by chance my answer was so close. I extracted the test cases containing origin (with your alogorith) and compared them with mine. Here are 2(out of 60) of the coordinates rejected by my algorithm but accepted by yours $(244, -276, 713, 330, -897, -214),(-105, 918, 188, 237, -110, -591)$ and two accepted by mine but rejected by yours $(-226, -790, 28, -930, 827, 783),(-608, -273, -141, 930, 687, 380)$
$endgroup$
– Anvit
Dec 17 '18 at 11:51
add a comment |
$begingroup$
you might like to try an alternative method that may be more transparent and robust.
supposing Q lies within ABC. a test probe P moving from A towards B should initially observe a decrease in the distance $PQ = r_{lambda}$. if we parameterize the position of the probe as
$$
P_{lambda} = lambda A + (1-lambda) B
$$
then for an internal point $Q$ we should have:
$$
frac{d|P_lambda Q|^2}{dlambda}bigg|_{lambda= 0} lt 0
$$
if $A = (x_1,y_1), B= (x_2, y_2), C=(x_3,y_3)$, and $Q=(x_0, y_0)$ then this test computes as:
$$
(a_2-a_1)(a_1-a_0) +(b_2-b_1)(b_1-b_0) lt 0
$$
with similar tests for the other two sides, BC and CA, obtained by cyclic permutation.
$endgroup$
add a comment |
$begingroup$
you might like to try an alternative method that may be more transparent and robust.
supposing Q lies within ABC. a test probe P moving from A towards B should initially observe a decrease in the distance $PQ = r_{lambda}$. if we parameterize the position of the probe as
$$
P_{lambda} = lambda A + (1-lambda) B
$$
then for an internal point $Q$ we should have:
$$
frac{d|P_lambda Q|^2}{dlambda}bigg|_{lambda= 0} lt 0
$$
if $A = (x_1,y_1), B= (x_2, y_2), C=(x_3,y_3)$, and $Q=(x_0, y_0)$ then this test computes as:
$$
(a_2-a_1)(a_1-a_0) +(b_2-b_1)(b_1-b_0) lt 0
$$
with similar tests for the other two sides, BC and CA, obtained by cyclic permutation.
$endgroup$
add a comment |
$begingroup$
you might like to try an alternative method that may be more transparent and robust.
supposing Q lies within ABC. a test probe P moving from A towards B should initially observe a decrease in the distance $PQ = r_{lambda}$. if we parameterize the position of the probe as
$$
P_{lambda} = lambda A + (1-lambda) B
$$
then for an internal point $Q$ we should have:
$$
frac{d|P_lambda Q|^2}{dlambda}bigg|_{lambda= 0} lt 0
$$
if $A = (x_1,y_1), B= (x_2, y_2), C=(x_3,y_3)$, and $Q=(x_0, y_0)$ then this test computes as:
$$
(a_2-a_1)(a_1-a_0) +(b_2-b_1)(b_1-b_0) lt 0
$$
with similar tests for the other two sides, BC and CA, obtained by cyclic permutation.
$endgroup$
you might like to try an alternative method that may be more transparent and robust.
supposing Q lies within ABC. a test probe P moving from A towards B should initially observe a decrease in the distance $PQ = r_{lambda}$. if we parameterize the position of the probe as
$$
P_{lambda} = lambda A + (1-lambda) B
$$
then for an internal point $Q$ we should have:
$$
frac{d|P_lambda Q|^2}{dlambda}bigg|_{lambda= 0} lt 0
$$
if $A = (x_1,y_1), B= (x_2, y_2), C=(x_3,y_3)$, and $Q=(x_0, y_0)$ then this test computes as:
$$
(a_2-a_1)(a_1-a_0) +(b_2-b_1)(b_1-b_0) lt 0
$$
with similar tests for the other two sides, BC and CA, obtained by cyclic permutation.
answered Dec 17 '18 at 11:27
David HoldenDavid Holden
14.9k21225
14.9k21225
add a comment |
add a comment |
$begingroup$
If the point is in the $3^{rd}$ quadrant, the angle it makes with the $x$ axis in the anti-clockwise direction is $180+arctan(Big|frac yxBig|)$
$endgroup$
add a comment |
$begingroup$
If the point is in the $3^{rd}$ quadrant, the angle it makes with the $x$ axis in the anti-clockwise direction is $180+arctan(Big|frac yxBig|)$
$endgroup$
add a comment |
$begingroup$
If the point is in the $3^{rd}$ quadrant, the angle it makes with the $x$ axis in the anti-clockwise direction is $180+arctan(Big|frac yxBig|)$
$endgroup$
If the point is in the $3^{rd}$ quadrant, the angle it makes with the $x$ axis in the anti-clockwise direction is $180+arctan(Big|frac yxBig|)$
answered Dec 17 '18 at 12:23
Shubham JohriShubham Johri
5,204718
5,204718
add a comment |
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3043778%2falgorithm-to-find-if-a-triangle-with-given-vertices-contains-a-point-p%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
You answered your own question. It is obviously not correct since $232 ne 228$.
$endgroup$
– gammatester
Dec 17 '18 at 10:38
$begingroup$
@gammatester What is the error in the algorithm then?
$endgroup$
– Anvit
Dec 17 '18 at 10:40
$begingroup$
I do not know, but it is rather obscure. I suggest you have a close look at the test cases that were wrong.
$endgroup$
– gammatester
Dec 17 '18 at 10:49
$begingroup$
@gammatester. Thats the problem. I dont know which test cases are wrong. Is these some other method to verify?
$endgroup$
– Anvit
Dec 17 '18 at 10:51
$begingroup$
Huh? How do you know that they are wrong? If you search an algorithm look e.g. at mochima.com/articles/cuj_geometry_article/… and cs.cmu.edu/~quake/robust.html
$endgroup$
– gammatester
Dec 17 '18 at 10:56