LoginSignup
3
1

More than 5 years have passed since last update.

Ruby Vectorで2点間の距離を求める

Posted at
require "matrix"

v1 = Vector[14.0, 21.0]
v2 = Vector[17.0, 17.0]
(v2 - v1).r
  # => 5.0
  # (v2 - v1).magnitude
  # (v2 - v1).norm
  # も同じ
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1