Quick and dirty test.
(I hope I did not made a mistake)
#@Aerilius
def p_b2_Ae(qp, p1, p2)
[0, 1, 2].each{ |x| unless (p1[x] <= qp[x] && qp[x] <= p2[x]) || (p2[x] <= qp[x] && qp[x] <= p1[x])
return false
end
}
return qp.on_line?([p1, p2])
end
#@kirill200777
def p_b2_ki(qp, p1, p2)
d1=qp.distance(p1)
d2=qp.distance(p2)
edg_len=p1.distance(p2)
on_edge=true
on_edge=false if edg_len<d1+d2
on_edge
end
#@DanRathbun
def p_b2_Da(qp, p1, p2)
return true if qp == p1 || qp == p2
qp.on_line?([p1, p2]) && !qp.vector_to(p1).samedirection?(qp.vector_to(p2))
end
#@dezmo
def p_b2_De(qp, p1, p2)
boundingbox = Geom::BoundingBox.new
boundingbox.add( p1, p2)
boundingbox.contains?(qp) && qp.on_line?([p1, p2])
end
#Test
p1=[0,0,0];p2=[10,10,10]
(1..3).each{|i|
puts
qp=[0,0,0]if i==1
qp=[1,1,1] if i==2
qp=[0,0,100] if i==3
puts "Test #{i}: Is qp=#{qp} on the edge between p1=#{p1} & p2=#{p2}?"
start = Time.now
1000000.times{ p_b2_Ae(qp, p1, p2)}
puts "p_b2_Ae: #{Time.now-start} #{p_b2_Ae(qp, p1, p2)}"
start = Time.now
1000000.times{ p_b2_ki(qp, p1, p2)}
puts "p_b2_ki: #{Time.now-start} #{p_b2_ki(qp, p1, p2)}"
start = Time.now
1000000.times{ p_b2_Da(qp, p1, p2)}
puts "p_b2_Da: #{Time.now-start} #{p_b2_Da(qp, p1, p2)}"
start = Time.now
1000000.times{ p_b2_De(qp, p1, p2)}
puts "p_b2_De: #{Time.now-start} #{p_b2_De(qp, p1, p2)}"
puts
}
The tets result:
(DellM4700, corei7(gen4), NVIDIA QK1000M, W7/32bit, SU2014Pro)
Test 1: Is qp=[0, 0, 0] on the edge between p1=[0, 0, 0] & p2=[10, 10, 10]?
p_b2_Ae: 1.567784 true
p_b2_ki: 1.976988 true
p_b2_Da: 0.261131 true
p_b2_De: 2.170085 true
Test 2: Is qp=[1, 1, 1] on the edge between p1=[0, 0, 0] & p2=[10, 10, 10]?
p_b2_Ae: 1.588794 true
p_b2_ki: 1.944972 true
p_b2_Da: 2.897448 true
p_b2_De: 2.103051 true
Test 3: Is qp=[0, 0, 100] on the edge between p1=[0, 0, 0] & p2=[10, 10, 10]?
p_b2_Ae: 0.815408 false
p_b2_ki: 1.957978 false
p_b2_Da: 1.488744 false
p_b2_De: 1.238619 false
Interesting result, for sure depends on the points positions.
I don’t know exactly what the conclusions are…?