class PinBall_Edge
  attr_accessor :restitution
  attr_accessor :vertices
  
  def initialize(vertices , restitution)
    @vertices = vertices
    @restitution = restitution
    
  end  
  
  
  #●方向のベクトルを求める
  def direction_vector
    vertex = @vertices[0] 
    nvertex = @vertices[1] 
    return [nvertex.x - vertex.x , nvertex.y - vertex.y]
  end  

  #●法線ベクトルを求める 
  def normal_vector
    [direction_vector[1] , - direction_vector[0]] 
  end  
     
  
  #●正規化した法線ベクトル
  def normalized_normal_vector
    VectorCalc.normalize(normal_vector)
  end    
  
  #●傾き具合
  def tangent
    direction_vector[1] / direction_vector[0]
    
  end    
  
  #●
  def y_value(x)
    return nil if direction_vector[0] == 0 # 指定しない
    return tangent * (x -  @vertices[0].x) + @vertices[0].y
  end  
  
  #●
  def x_value(y)
    return nil if direction_vector[1] == 0 # 指定しない
    return (1 / tangent) * (y -  @vertices[0].y) + @vertices[0].x
  end    
  
end  