Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created March 18, 2018 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maehrm/a5522832f9467755f3e251043a6382c7 to your computer and use it in GitHub Desktop.
Save maehrm/a5522832f9467755f3e251043a6382c7 to your computer and use it in GitHub Desktop.
反時計回り | 計算幾何学 | Aizu Online Judge http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C&lang=jp
# coding: utf-8
require 'matrix'
xp0, yp0, xp1, yp1 = gets.split.map(&:to_f)
p01 = Vector[xp1-xp0, yp1-yp0]
gets.to_i.times {
xp2, yp2 = gets.split.map(&:to_f)
p02 = Vector[xp2-xp0, yp2-yp0]
cross = p01[0]*p02[1]-p01[1]*p02[0] # 外積
# cross = p01.cross(p02) # wrong number of arguments (1 for 0) (ArgumentError)
if cross > 0
puts "COUNTER_CLOCKWISE"
elsif cross < 0
puts "CLOCKWISE"
else
dot = p01.dot(p02)
if dot < 0
puts "ONLINE_BACK"
else
if p01.r >= p02.r
puts "ON_SEGMENT"
else
puts "ONLINE_FRONT"
end
end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment