lib/measures/tbd/resources/psi.rb
##
# Validate whether edge surfaces form a convex angle, as seen from outside.
#
# @param [Surface] s1 A first TBD surface
# @param [Surface] s2 A second TBD surface
#
# @return [Bool] Returns true if angle between surfaces is convex
Validate whether edge surfaces form a convex angle, as seen from outside.
Validate whether edge surfaces form a convex angle as seen from outside .
def convex?(s1, s2)
  unless s1.is_a?(Hash)            && s2.is_a?(Hash)            &&
         s1.has_key?(:angle)       && s2.has_key?(:angle)       &&
         s1[:angle].is_a?(Numeric) && s2[:angle].is_a?(Numeric) &&
         s1.has_key?(:normal)      && s2.has_key?(:normal)      &&
         s1.has_key?(:polar)       && s2.has_key?(:polar)
    TBD.log(TBD::DEBUG,
      "Invalid arguments determining convexity - skipping")
    return false
  end
  angle = 0
  angle = s2[:angle] - s1[:angle] if s2[:angle] > s1[:angle]
  angle = s1[:angle] - s2[:angle] if s1[:angle] > s2[:angle]
  return false if angle < TOL
  return false unless (2 * Math::PI - angle).abs > TOL
  return false if angle > 3 * Math::PI / 4 && angle < 5 * Math::PI / 4
  n1_d_p2 = s1[:normal].dot(s2[:polar])
  p1_d_n2 = s1[:polar].dot(s2[:normal])
  return true if n1_d_p2 < 0 && p1_d_n2 < 0
  false
end
def convex? ( s1 , s2 ) unless s1 . is_a? ( Hash ) && s2 . is_a? ( Hash ) && s1 . has_key? ( :angle ) && s2 . has_key? ( :angle ) && s1 [ :angle ] . is_a? ( Numeric ) && s2 [ :angle ] . is_a? ( Numeric ) && s1 . has_key? ( :normal ) && s2 . has_key? ( :normal ) && s1 . has_key? ( :polar ) && s2 . has_key? ( :polar ) TBD . log ( TBD :: DEBUG , "Invalid arguments determining convexity - skipping" ) return false end angle = 0 angle = s2 [ :angle ] - s1 [ :angle ] if s2 [ :angle ] > s1 [ :angle ] angle = s1 [ :angle ] - s2 [ :angle ] if s1 [ :angle ] > s2 [ :angle ] return false if angle < TOL return false unless ( 2 * Math :: PI - angle ) . abs > TOL return false if angle > 3 * Math :: PI / 4 && angle < 5 * Math :: PI / 4 n1_d_p2 = s1 [ :normal ] . dot ( s2 [ :polar ] ) p1_d_n2 = s1 [ :polar ] . dot ( s2 [ :normal ] ) return true if n1_d_p2 < 0 && p1_d_n2 < 0 false end
Validate whether edge surfaces form a convex angle, as seen from outside.
Validate whether edge surfaces form a convex angle as seen from outside .
Returns true if angle between surfaces is convex
Returns true if angle between surfaces is convex
Bool
s1
s2
s2 A second TBD surface
s2 A second TBD surface