Skip to main content
edited tags
Link
user45941
user45941
Tweeted twitter.com/#!/StackCodeGolf/status/60853741489885184
Added inline edge example
Source Link
Keith Randall
  • 21.1k
  • 2
  • 46
  • 106

Write a program to determine if the input polygon is convex. The polygon is specified with one line containing N, the number of vertices, then N lines containing the x and y coordinates of each vertex. The vertices will be listed clockwise starting from an arbitrary vertex.

##example 1

###input

4 0 0 0 1 1 1 1 0 

###output

convex 

##example 2

###input

4 0 0 2 1 1 0 2 -1 

###output

concave 

##example 3

###input

8 0 0 0 1 0 2 1 2 2 2 2 1 2 0 1 0 

###output

convex 

x and y are integers, N<1000, and |x|,|y|<1000. You may assume that the input polygon is simple (none of the edges cross, only 2 edges touch each vertex). Shortest program wins.

Write a program to determine if the input polygon is convex. The polygon is specified with one line containing N, the number of vertices, then N lines containing the x and y coordinates of each vertex. The vertices will be listed clockwise starting from an arbitrary vertex.

##example 1

###input

4 0 0 0 1 1 1 1 0 

###output

convex 

##example 2

###input

4 0 0 2 1 1 0 2 -1 

###output

concave 

x and y are integers, N<1000, and |x|,|y|<1000. You may assume that the input polygon is simple (none of the edges cross, only 2 edges touch each vertex). Shortest program wins.

Write a program to determine if the input polygon is convex. The polygon is specified with one line containing N, the number of vertices, then N lines containing the x and y coordinates of each vertex. The vertices will be listed clockwise starting from an arbitrary vertex.

##example 1

###input

4 0 0 0 1 1 1 1 0 

###output

convex 

##example 2

###input

4 0 0 2 1 1 0 2 -1 

###output

concave 

##example 3

###input

8 0 0 0 1 0 2 1 2 2 2 2 1 2 0 1 0 

###output

convex 

x and y are integers, N<1000, and |x|,|y|<1000. You may assume that the input polygon is simple (none of the edges cross, only 2 edges touch each vertex). Shortest program wins.

Source Link
Keith Randall
  • 21.1k
  • 2
  • 46
  • 106

Determine if a polygon is convex

Write a program to determine if the input polygon is convex. The polygon is specified with one line containing N, the number of vertices, then N lines containing the x and y coordinates of each vertex. The vertices will be listed clockwise starting from an arbitrary vertex.

##example 1

###input

4 0 0 0 1 1 1 1 0 

###output

convex 

##example 2

###input

4 0 0 2 1 1 0 2 -1 

###output

concave 

x and y are integers, N<1000, and |x|,|y|<1000. You may assume that the input polygon is simple (none of the edges cross, only 2 edges touch each vertex). Shortest program wins.