What is the difference between a line segment inside and outside of a concave polygon?What is the difference between old style and new style classes in Python?What is the difference between @staticmethod and @classmethod?What is the difference between Python's list methods append and extend?How do I efficiently determine if a polygon is convex, non-convex or complex?How do you detect where two line segments intersect?What's the difference between lists and tuples?Difference between __str__ and __repr__?What are the differences between type() and isinstance()?What is the difference between dict.items() and dict.iteritems()?furthest point inside polygon with orthogonal edges (convex or concave or having holes)

Scala list with same adjacent values

Modern approach to radio buttons

Term for checking piece whose opponent daren't capture it

Why use water tanks from a retired Space Shuttle?

Is American Express widely accepted in France?

How does increase in volume change the speed of reaction in production of NO2?

What does the behaviour of water on the skin of an aircraft in flight tell us?

How to detach yourself from a character you're going to kill?

If a problem only occurs randomly once in every N times on average, how many tests do I have to perform to be certain that it's now fixed?

Are grass strips more dangerous than tarmac?

How was Apollo supposed to rendezvous in the case of a lunar abort?

Is having a hidden directory under /etc safe?

Can you use a concentration spell while using Mantle of Majesty?

What are the problems in teaching guitar via Skype?

Did airlines fly their aircraft slower in response to oil prices in the 1970s?

Where can I find the list of all tendons in the human body?

Expenditure in Poland - Forex doesn't have Zloty

What is the difference between nullifying your vote and not going to vote at all?

How can an eldritch abomination hide its true form in public?

Humans meet a distant alien species. How do they standardize? - Units of Measure

Different PCB color ( is it different material? )

What is the most important characteristic of New Weird as a genre?

'chmod' would set file permission to 000 no matter what permission I try to set

arcpy.GetParameterAsText not passing arguments to script?



What is the difference between a line segment inside and outside of a concave polygon?


What is the difference between old style and new style classes in Python?What is the difference between @staticmethod and @classmethod?What is the difference between Python's list methods append and extend?How do I efficiently determine if a polygon is convex, non-convex or complex?How do you detect where two line segments intersect?What's the difference between lists and tuples?Difference between __str__ and __repr__?What are the differences between type() and isinstance()?What is the difference between dict.items() and dict.iteritems()?furthest point inside polygon with orthogonal edges (convex or concave or having holes)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















My question is about the creation of visibility graphs in surfaces with multiple convex and concave polygons. My problem is that i am not able to classify whether the line segments connecting the nodes of the same polygon go through or don't go through this polygon. As seen in the picture below:



example



I'd need to separate the orange, invalid lines from the blue, valid lines. I hope somebody can provide me a solution to this problem with a suitable algorithm that can be implemented in python.



Or for even complexer polygons?:
difficult polygon










share|improve this question



















  • 1





    In which form do you have the polygon?The coordinates of vertices?

    – Tojrah
    Mar 24 at 11:21











  • Exactly! I have the coordinates of all vertices.

    – Jonas Hasel
    Mar 24 at 11:25











  • Do you know which pairs of points (edges) conforms the boundary of the non-convex polygon?

    – Mauricio Cele Lopez Belon
    Mar 24 at 15:08











  • No, there's no more information than the vertices.

    – Jonas Hasel
    Mar 24 at 15:36











  • If you only have the vertex locations you don't really have a polygon. Given the vertices in the polygon shown above it's relatively straightforward to draw 2 or 3 different polygons. Which kind of makes 'insideness' tests difficult to implement.

    – High Performance Mark
    Mar 24 at 16:26

















2















My question is about the creation of visibility graphs in surfaces with multiple convex and concave polygons. My problem is that i am not able to classify whether the line segments connecting the nodes of the same polygon go through or don't go through this polygon. As seen in the picture below:



example



I'd need to separate the orange, invalid lines from the blue, valid lines. I hope somebody can provide me a solution to this problem with a suitable algorithm that can be implemented in python.



Or for even complexer polygons?:
difficult polygon










share|improve this question



















  • 1





    In which form do you have the polygon?The coordinates of vertices?

    – Tojrah
    Mar 24 at 11:21











  • Exactly! I have the coordinates of all vertices.

    – Jonas Hasel
    Mar 24 at 11:25











  • Do you know which pairs of points (edges) conforms the boundary of the non-convex polygon?

    – Mauricio Cele Lopez Belon
    Mar 24 at 15:08











  • No, there's no more information than the vertices.

    – Jonas Hasel
    Mar 24 at 15:36











  • If you only have the vertex locations you don't really have a polygon. Given the vertices in the polygon shown above it's relatively straightforward to draw 2 or 3 different polygons. Which kind of makes 'insideness' tests difficult to implement.

    – High Performance Mark
    Mar 24 at 16:26













2












2








2


1






My question is about the creation of visibility graphs in surfaces with multiple convex and concave polygons. My problem is that i am not able to classify whether the line segments connecting the nodes of the same polygon go through or don't go through this polygon. As seen in the picture below:



example



I'd need to separate the orange, invalid lines from the blue, valid lines. I hope somebody can provide me a solution to this problem with a suitable algorithm that can be implemented in python.



Or for even complexer polygons?:
difficult polygon










share|improve this question
















My question is about the creation of visibility graphs in surfaces with multiple convex and concave polygons. My problem is that i am not able to classify whether the line segments connecting the nodes of the same polygon go through or don't go through this polygon. As seen in the picture below:



example



I'd need to separate the orange, invalid lines from the blue, valid lines. I hope somebody can provide me a solution to this problem with a suitable algorithm that can be implemented in python.



Or for even complexer polygons?:
difficult polygon







python graph geometry polygon concave






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 20:51







Jonas Hasel

















asked Mar 24 at 11:06









Jonas HaselJonas Hasel

134




134







  • 1





    In which form do you have the polygon?The coordinates of vertices?

    – Tojrah
    Mar 24 at 11:21











  • Exactly! I have the coordinates of all vertices.

    – Jonas Hasel
    Mar 24 at 11:25











  • Do you know which pairs of points (edges) conforms the boundary of the non-convex polygon?

    – Mauricio Cele Lopez Belon
    Mar 24 at 15:08











  • No, there's no more information than the vertices.

    – Jonas Hasel
    Mar 24 at 15:36











  • If you only have the vertex locations you don't really have a polygon. Given the vertices in the polygon shown above it's relatively straightforward to draw 2 or 3 different polygons. Which kind of makes 'insideness' tests difficult to implement.

    – High Performance Mark
    Mar 24 at 16:26












  • 1





    In which form do you have the polygon?The coordinates of vertices?

    – Tojrah
    Mar 24 at 11:21











  • Exactly! I have the coordinates of all vertices.

    – Jonas Hasel
    Mar 24 at 11:25











  • Do you know which pairs of points (edges) conforms the boundary of the non-convex polygon?

    – Mauricio Cele Lopez Belon
    Mar 24 at 15:08











  • No, there's no more information than the vertices.

    – Jonas Hasel
    Mar 24 at 15:36











  • If you only have the vertex locations you don't really have a polygon. Given the vertices in the polygon shown above it's relatively straightforward to draw 2 or 3 different polygons. Which kind of makes 'insideness' tests difficult to implement.

    – High Performance Mark
    Mar 24 at 16:26







1




1





In which form do you have the polygon?The coordinates of vertices?

– Tojrah
Mar 24 at 11:21





In which form do you have the polygon?The coordinates of vertices?

– Tojrah
Mar 24 at 11:21













Exactly! I have the coordinates of all vertices.

– Jonas Hasel
Mar 24 at 11:25





Exactly! I have the coordinates of all vertices.

– Jonas Hasel
Mar 24 at 11:25













Do you know which pairs of points (edges) conforms the boundary of the non-convex polygon?

– Mauricio Cele Lopez Belon
Mar 24 at 15:08





Do you know which pairs of points (edges) conforms the boundary of the non-convex polygon?

– Mauricio Cele Lopez Belon
Mar 24 at 15:08













No, there's no more information than the vertices.

– Jonas Hasel
Mar 24 at 15:36





No, there's no more information than the vertices.

– Jonas Hasel
Mar 24 at 15:36













If you only have the vertex locations you don't really have a polygon. Given the vertices in the polygon shown above it's relatively straightforward to draw 2 or 3 different polygons. Which kind of makes 'insideness' tests difficult to implement.

– High Performance Mark
Mar 24 at 16:26





If you only have the vertex locations you don't really have a polygon. Given the vertices in the polygon shown above it's relatively straightforward to draw 2 or 3 different polygons. Which kind of makes 'insideness' tests difficult to implement.

– High Performance Mark
Mar 24 at 16:26












1 Answer
1






active

oldest

votes


















0














this image explains the three casesThis code accepts A and B as two vertices and checks if the line joining them lies completely inside , partially inside or completely outside the polygon. This is based on mathematical fact that for a line with eqn. F(X,y):Ax+By+C the point x1,y1 will lie on the line if F(x1,y1)=0
On one side of line if F(x1,y1)>0
On other side of line if F(x1,y1)<0



L=[] #list of all the vertices of the polygon as (x,y) tuples in order
A=()
B=()
# A and B are tuples of coordinates of points joking diagonal to check
def eqn(A,B):
X1=A[0];Y1=A[1]
X2=B[0];Y2=B[1]
return(X2-X1,Y1-Y2,X1*Y2-X2*Y1)
def check(Y,X,C,y,x):
if(Y*y+X*X+C>0):
return 1
elif(Y*y+X*X+C<0):
return -1
else:
return 0

Y,X,C=eqn(A,B)
#get parameters of diagonal joining A and B
a=L.index(A)
b=L.index(B)
L1=[]
L2=[]
if(a>b):
L1=L[b+1:a]
L2=L[a+1:]+L[:b]
elif(b>a):
L1=L[a+1:b]
L2=L[b+1:]+L[:a]
#so I have split the list into two lists L1 and L2 containing vertices in cyclic order on either side of the diagonal
k=1
m=0
val1=check(Y,X,C,L1[0][1],L1[0][0])
val2=check(Y,X,C,L2[0][1],L2[0][0])
if(val1==val2):
k=0
m=1
else:
# I have to check F(x,y) for each point in list L1 and L2 it should be of one sign for all elements in L1 and of other sign for all elements in L2 for line to lie completely inside polygon
for t in L1:
if(check(Y,X,C,t[1],t[0])!=val1):
k=0
m=0
for s in L2:
if(check(Y,X,C,s[1],s[0])!=val2):
k=0
m=0
if(k==0):
print('the diagonal passes outside')
else:
print('the diagonal lies completely inside the polygon')
if(m==1):
print('the diagonal lies completely outside the polygon')


I have written the code hope it works as required,but there maybe errors:o,the logic is correct,there may be syntax or other errors you have to take care of(I can help in that case) I have excluded one case if the two points chosen are consecutive,then it is obviously the side of the polygon(trivial to check).






share|improve this answer

























  • Hello, thank you for providing a solution but I get a list index out of range error in either line 32 or line 33 depending on my A and B. For which python version is this code?

    – Jonas Hasel
    Mar 24 at 15:53











  • The code is for python3. Please provide the line. Is the error only for some values of A and B

    – Tojrah
    Mar 24 at 15:56











  • These are the two lines: val1=check(Y,X,C,L1[0][1],L1[0][0]) val2=check(Y,X,C,L2[0][1],L2[0][0])

    – Jonas Hasel
    Mar 24 at 15:58












  • And could you please the concept a bit more because i didn't understand it 100%

    – Jonas Hasel
    Mar 24 at 16:00











  • So we draw a diagonal. The diagonal divides the vertices of polygon into two groups (lists L1 and L2). Each on either side of the diagonal(I have excluded the points on the diagonal A and B). So then I check for each point in the lists. If each point in L1 is on one side of the diagonal and each point in L2 is in the other side of the diagonal the, the diagonal lies completely inside the polygon. Now if any vertex in either list is on the other side of the diagonal as compared to other points in the same list , we say the diagonal is partially inside and partially outside the polygon .

    – Tojrah
    Mar 24 at 16:11











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55323147%2fwhat-is-the-difference-between-a-line-segment-inside-and-outside-of-a-concave-po%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














this image explains the three casesThis code accepts A and B as two vertices and checks if the line joining them lies completely inside , partially inside or completely outside the polygon. This is based on mathematical fact that for a line with eqn. F(X,y):Ax+By+C the point x1,y1 will lie on the line if F(x1,y1)=0
On one side of line if F(x1,y1)>0
On other side of line if F(x1,y1)<0



L=[] #list of all the vertices of the polygon as (x,y) tuples in order
A=()
B=()
# A and B are tuples of coordinates of points joking diagonal to check
def eqn(A,B):
X1=A[0];Y1=A[1]
X2=B[0];Y2=B[1]
return(X2-X1,Y1-Y2,X1*Y2-X2*Y1)
def check(Y,X,C,y,x):
if(Y*y+X*X+C>0):
return 1
elif(Y*y+X*X+C<0):
return -1
else:
return 0

Y,X,C=eqn(A,B)
#get parameters of diagonal joining A and B
a=L.index(A)
b=L.index(B)
L1=[]
L2=[]
if(a>b):
L1=L[b+1:a]
L2=L[a+1:]+L[:b]
elif(b>a):
L1=L[a+1:b]
L2=L[b+1:]+L[:a]
#so I have split the list into two lists L1 and L2 containing vertices in cyclic order on either side of the diagonal
k=1
m=0
val1=check(Y,X,C,L1[0][1],L1[0][0])
val2=check(Y,X,C,L2[0][1],L2[0][0])
if(val1==val2):
k=0
m=1
else:
# I have to check F(x,y) for each point in list L1 and L2 it should be of one sign for all elements in L1 and of other sign for all elements in L2 for line to lie completely inside polygon
for t in L1:
if(check(Y,X,C,t[1],t[0])!=val1):
k=0
m=0
for s in L2:
if(check(Y,X,C,s[1],s[0])!=val2):
k=0
m=0
if(k==0):
print('the diagonal passes outside')
else:
print('the diagonal lies completely inside the polygon')
if(m==1):
print('the diagonal lies completely outside the polygon')


I have written the code hope it works as required,but there maybe errors:o,the logic is correct,there may be syntax or other errors you have to take care of(I can help in that case) I have excluded one case if the two points chosen are consecutive,then it is obviously the side of the polygon(trivial to check).






share|improve this answer

























  • Hello, thank you for providing a solution but I get a list index out of range error in either line 32 or line 33 depending on my A and B. For which python version is this code?

    – Jonas Hasel
    Mar 24 at 15:53











  • The code is for python3. Please provide the line. Is the error only for some values of A and B

    – Tojrah
    Mar 24 at 15:56











  • These are the two lines: val1=check(Y,X,C,L1[0][1],L1[0][0]) val2=check(Y,X,C,L2[0][1],L2[0][0])

    – Jonas Hasel
    Mar 24 at 15:58












  • And could you please the concept a bit more because i didn't understand it 100%

    – Jonas Hasel
    Mar 24 at 16:00











  • So we draw a diagonal. The diagonal divides the vertices of polygon into two groups (lists L1 and L2). Each on either side of the diagonal(I have excluded the points on the diagonal A and B). So then I check for each point in the lists. If each point in L1 is on one side of the diagonal and each point in L2 is in the other side of the diagonal the, the diagonal lies completely inside the polygon. Now if any vertex in either list is on the other side of the diagonal as compared to other points in the same list , we say the diagonal is partially inside and partially outside the polygon .

    – Tojrah
    Mar 24 at 16:11















0














this image explains the three casesThis code accepts A and B as two vertices and checks if the line joining them lies completely inside , partially inside or completely outside the polygon. This is based on mathematical fact that for a line with eqn. F(X,y):Ax+By+C the point x1,y1 will lie on the line if F(x1,y1)=0
On one side of line if F(x1,y1)>0
On other side of line if F(x1,y1)<0



L=[] #list of all the vertices of the polygon as (x,y) tuples in order
A=()
B=()
# A and B are tuples of coordinates of points joking diagonal to check
def eqn(A,B):
X1=A[0];Y1=A[1]
X2=B[0];Y2=B[1]
return(X2-X1,Y1-Y2,X1*Y2-X2*Y1)
def check(Y,X,C,y,x):
if(Y*y+X*X+C>0):
return 1
elif(Y*y+X*X+C<0):
return -1
else:
return 0

Y,X,C=eqn(A,B)
#get parameters of diagonal joining A and B
a=L.index(A)
b=L.index(B)
L1=[]
L2=[]
if(a>b):
L1=L[b+1:a]
L2=L[a+1:]+L[:b]
elif(b>a):
L1=L[a+1:b]
L2=L[b+1:]+L[:a]
#so I have split the list into two lists L1 and L2 containing vertices in cyclic order on either side of the diagonal
k=1
m=0
val1=check(Y,X,C,L1[0][1],L1[0][0])
val2=check(Y,X,C,L2[0][1],L2[0][0])
if(val1==val2):
k=0
m=1
else:
# I have to check F(x,y) for each point in list L1 and L2 it should be of one sign for all elements in L1 and of other sign for all elements in L2 for line to lie completely inside polygon
for t in L1:
if(check(Y,X,C,t[1],t[0])!=val1):
k=0
m=0
for s in L2:
if(check(Y,X,C,s[1],s[0])!=val2):
k=0
m=0
if(k==0):
print('the diagonal passes outside')
else:
print('the diagonal lies completely inside the polygon')
if(m==1):
print('the diagonal lies completely outside the polygon')


I have written the code hope it works as required,but there maybe errors:o,the logic is correct,there may be syntax or other errors you have to take care of(I can help in that case) I have excluded one case if the two points chosen are consecutive,then it is obviously the side of the polygon(trivial to check).






share|improve this answer

























  • Hello, thank you for providing a solution but I get a list index out of range error in either line 32 or line 33 depending on my A and B. For which python version is this code?

    – Jonas Hasel
    Mar 24 at 15:53











  • The code is for python3. Please provide the line. Is the error only for some values of A and B

    – Tojrah
    Mar 24 at 15:56











  • These are the two lines: val1=check(Y,X,C,L1[0][1],L1[0][0]) val2=check(Y,X,C,L2[0][1],L2[0][0])

    – Jonas Hasel
    Mar 24 at 15:58












  • And could you please the concept a bit more because i didn't understand it 100%

    – Jonas Hasel
    Mar 24 at 16:00











  • So we draw a diagonal. The diagonal divides the vertices of polygon into two groups (lists L1 and L2). Each on either side of the diagonal(I have excluded the points on the diagonal A and B). So then I check for each point in the lists. If each point in L1 is on one side of the diagonal and each point in L2 is in the other side of the diagonal the, the diagonal lies completely inside the polygon. Now if any vertex in either list is on the other side of the diagonal as compared to other points in the same list , we say the diagonal is partially inside and partially outside the polygon .

    – Tojrah
    Mar 24 at 16:11













0












0








0







this image explains the three casesThis code accepts A and B as two vertices and checks if the line joining them lies completely inside , partially inside or completely outside the polygon. This is based on mathematical fact that for a line with eqn. F(X,y):Ax+By+C the point x1,y1 will lie on the line if F(x1,y1)=0
On one side of line if F(x1,y1)>0
On other side of line if F(x1,y1)<0



L=[] #list of all the vertices of the polygon as (x,y) tuples in order
A=()
B=()
# A and B are tuples of coordinates of points joking diagonal to check
def eqn(A,B):
X1=A[0];Y1=A[1]
X2=B[0];Y2=B[1]
return(X2-X1,Y1-Y2,X1*Y2-X2*Y1)
def check(Y,X,C,y,x):
if(Y*y+X*X+C>0):
return 1
elif(Y*y+X*X+C<0):
return -1
else:
return 0

Y,X,C=eqn(A,B)
#get parameters of diagonal joining A and B
a=L.index(A)
b=L.index(B)
L1=[]
L2=[]
if(a>b):
L1=L[b+1:a]
L2=L[a+1:]+L[:b]
elif(b>a):
L1=L[a+1:b]
L2=L[b+1:]+L[:a]
#so I have split the list into two lists L1 and L2 containing vertices in cyclic order on either side of the diagonal
k=1
m=0
val1=check(Y,X,C,L1[0][1],L1[0][0])
val2=check(Y,X,C,L2[0][1],L2[0][0])
if(val1==val2):
k=0
m=1
else:
# I have to check F(x,y) for each point in list L1 and L2 it should be of one sign for all elements in L1 and of other sign for all elements in L2 for line to lie completely inside polygon
for t in L1:
if(check(Y,X,C,t[1],t[0])!=val1):
k=0
m=0
for s in L2:
if(check(Y,X,C,s[1],s[0])!=val2):
k=0
m=0
if(k==0):
print('the diagonal passes outside')
else:
print('the diagonal lies completely inside the polygon')
if(m==1):
print('the diagonal lies completely outside the polygon')


I have written the code hope it works as required,but there maybe errors:o,the logic is correct,there may be syntax or other errors you have to take care of(I can help in that case) I have excluded one case if the two points chosen are consecutive,then it is obviously the side of the polygon(trivial to check).






share|improve this answer















this image explains the three casesThis code accepts A and B as two vertices and checks if the line joining them lies completely inside , partially inside or completely outside the polygon. This is based on mathematical fact that for a line with eqn. F(X,y):Ax+By+C the point x1,y1 will lie on the line if F(x1,y1)=0
On one side of line if F(x1,y1)>0
On other side of line if F(x1,y1)<0



L=[] #list of all the vertices of the polygon as (x,y) tuples in order
A=()
B=()
# A and B are tuples of coordinates of points joking diagonal to check
def eqn(A,B):
X1=A[0];Y1=A[1]
X2=B[0];Y2=B[1]
return(X2-X1,Y1-Y2,X1*Y2-X2*Y1)
def check(Y,X,C,y,x):
if(Y*y+X*X+C>0):
return 1
elif(Y*y+X*X+C<0):
return -1
else:
return 0

Y,X,C=eqn(A,B)
#get parameters of diagonal joining A and B
a=L.index(A)
b=L.index(B)
L1=[]
L2=[]
if(a>b):
L1=L[b+1:a]
L2=L[a+1:]+L[:b]
elif(b>a):
L1=L[a+1:b]
L2=L[b+1:]+L[:a]
#so I have split the list into two lists L1 and L2 containing vertices in cyclic order on either side of the diagonal
k=1
m=0
val1=check(Y,X,C,L1[0][1],L1[0][0])
val2=check(Y,X,C,L2[0][1],L2[0][0])
if(val1==val2):
k=0
m=1
else:
# I have to check F(x,y) for each point in list L1 and L2 it should be of one sign for all elements in L1 and of other sign for all elements in L2 for line to lie completely inside polygon
for t in L1:
if(check(Y,X,C,t[1],t[0])!=val1):
k=0
m=0
for s in L2:
if(check(Y,X,C,s[1],s[0])!=val2):
k=0
m=0
if(k==0):
print('the diagonal passes outside')
else:
print('the diagonal lies completely inside the polygon')
if(m==1):
print('the diagonal lies completely outside the polygon')


I have written the code hope it works as required,but there maybe errors:o,the logic is correct,there may be syntax or other errors you have to take care of(I can help in that case) I have excluded one case if the two points chosen are consecutive,then it is obviously the side of the polygon(trivial to check).







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 24 at 16:22

























answered Mar 24 at 14:59









TojrahTojrah

506116




506116












  • Hello, thank you for providing a solution but I get a list index out of range error in either line 32 or line 33 depending on my A and B. For which python version is this code?

    – Jonas Hasel
    Mar 24 at 15:53











  • The code is for python3. Please provide the line. Is the error only for some values of A and B

    – Tojrah
    Mar 24 at 15:56











  • These are the two lines: val1=check(Y,X,C,L1[0][1],L1[0][0]) val2=check(Y,X,C,L2[0][1],L2[0][0])

    – Jonas Hasel
    Mar 24 at 15:58












  • And could you please the concept a bit more because i didn't understand it 100%

    – Jonas Hasel
    Mar 24 at 16:00











  • So we draw a diagonal. The diagonal divides the vertices of polygon into two groups (lists L1 and L2). Each on either side of the diagonal(I have excluded the points on the diagonal A and B). So then I check for each point in the lists. If each point in L1 is on one side of the diagonal and each point in L2 is in the other side of the diagonal the, the diagonal lies completely inside the polygon. Now if any vertex in either list is on the other side of the diagonal as compared to other points in the same list , we say the diagonal is partially inside and partially outside the polygon .

    – Tojrah
    Mar 24 at 16:11

















  • Hello, thank you for providing a solution but I get a list index out of range error in either line 32 or line 33 depending on my A and B. For which python version is this code?

    – Jonas Hasel
    Mar 24 at 15:53











  • The code is for python3. Please provide the line. Is the error only for some values of A and B

    – Tojrah
    Mar 24 at 15:56











  • These are the two lines: val1=check(Y,X,C,L1[0][1],L1[0][0]) val2=check(Y,X,C,L2[0][1],L2[0][0])

    – Jonas Hasel
    Mar 24 at 15:58












  • And could you please the concept a bit more because i didn't understand it 100%

    – Jonas Hasel
    Mar 24 at 16:00











  • So we draw a diagonal. The diagonal divides the vertices of polygon into two groups (lists L1 and L2). Each on either side of the diagonal(I have excluded the points on the diagonal A and B). So then I check for each point in the lists. If each point in L1 is on one side of the diagonal and each point in L2 is in the other side of the diagonal the, the diagonal lies completely inside the polygon. Now if any vertex in either list is on the other side of the diagonal as compared to other points in the same list , we say the diagonal is partially inside and partially outside the polygon .

    – Tojrah
    Mar 24 at 16:11
















Hello, thank you for providing a solution but I get a list index out of range error in either line 32 or line 33 depending on my A and B. For which python version is this code?

– Jonas Hasel
Mar 24 at 15:53





Hello, thank you for providing a solution but I get a list index out of range error in either line 32 or line 33 depending on my A and B. For which python version is this code?

– Jonas Hasel
Mar 24 at 15:53













The code is for python3. Please provide the line. Is the error only for some values of A and B

– Tojrah
Mar 24 at 15:56





The code is for python3. Please provide the line. Is the error only for some values of A and B

– Tojrah
Mar 24 at 15:56













These are the two lines: val1=check(Y,X,C,L1[0][1],L1[0][0]) val2=check(Y,X,C,L2[0][1],L2[0][0])

– Jonas Hasel
Mar 24 at 15:58






These are the two lines: val1=check(Y,X,C,L1[0][1],L1[0][0]) val2=check(Y,X,C,L2[0][1],L2[0][0])

– Jonas Hasel
Mar 24 at 15:58














And could you please the concept a bit more because i didn't understand it 100%

– Jonas Hasel
Mar 24 at 16:00





And could you please the concept a bit more because i didn't understand it 100%

– Jonas Hasel
Mar 24 at 16:00













So we draw a diagonal. The diagonal divides the vertices of polygon into two groups (lists L1 and L2). Each on either side of the diagonal(I have excluded the points on the diagonal A and B). So then I check for each point in the lists. If each point in L1 is on one side of the diagonal and each point in L2 is in the other side of the diagonal the, the diagonal lies completely inside the polygon. Now if any vertex in either list is on the other side of the diagonal as compared to other points in the same list , we say the diagonal is partially inside and partially outside the polygon .

– Tojrah
Mar 24 at 16:11





So we draw a diagonal. The diagonal divides the vertices of polygon into two groups (lists L1 and L2). Each on either side of the diagonal(I have excluded the points on the diagonal A and B). So then I check for each point in the lists. If each point in L1 is on one side of the diagonal and each point in L2 is in the other side of the diagonal the, the diagonal lies completely inside the polygon. Now if any vertex in either list is on the other side of the diagonal as compared to other points in the same list , we say the diagonal is partially inside and partially outside the polygon .

– Tojrah
Mar 24 at 16:11

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • 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.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55323147%2fwhat-is-the-difference-between-a-line-segment-inside-and-outside-of-a-concave-po%23new-answer', 'question_page');

);

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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript