本文整理汇总了Python中Geometry.to_vector方法的典型用法代码示例。如果您正苦于以下问题:Python Geometry.to_vector方法的具体用法?Python Geometry.to_vector怎么用?Python Geometry.to_vector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Geometry
的用法示例。
在下文中一共展示了Geometry.to_vector方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_mouse_stuff
# 需要导入模块: import Geometry [as 别名]
# 或者: from Geometry import to_vector [as 别名]
def do_mouse_stuff(self, hand): #Take a hand and use it as a mouse
hand_normal_direction = Geometry.to_vector(hand.palm_normal)
hand_direction = Geometry.to_vector(hand.direction)
roll = hand_normal_direction.roll()
pitch = hand_normal_direction.pitch()
mouse_velocity = self.convert_angles_to_mouse_velocity(roll, pitch)
self.cursor.move(mouse_velocity[0], mouse_velocity[1])
示例2: do_scroll_continuous
# 需要导入模块: import Geometry [as 别名]
# 或者: from Geometry import to_vector [as 别名]
def do_scroll_continuous(self, hand):
hand_normal_direction = Geometry.to_vector(hand.palm_normal)
hand_direction = Geometry.to_vector(hand.direction)
roll = hand_normal_direction.roll()
pitch = hand_normal_direction.pitch()
velocity = self.convert_angles_to_mouse_velocity(roll, pitch) * 100
self.cursor.scroll(velocity[0], velocity[1])
示例3: has_two_pointer_fingers
# 需要导入模块: import Geometry [as 别名]
# 或者: from Geometry import to_vector [as 别名]
def has_two_pointer_fingers(hand): #Checks if we are using two pointer fingers
if len(hand.fingers) < 2: #Obviously not
return False
sorted_fingers = sort_fingers_by_distance_from_screen(hand.fingers)
finger1_pos = Geometry.to_vector(sorted_fingers[0].tip_position)
finger2_pos = Geometry.to_vector(sorted_fingers[1].tip_position)
difference = finger1_pos - finger2_pos
if difference.norm() < 40: #Check if the fingertips are close together
return True
else:
return False
示例4: has_thumb
# 需要导入模块: import Geometry [as 别名]
# 或者: from Geometry import to_vector [as 别名]
def has_thumb(hand): #The level of accuracy with this function is surprisingly high
if hand.fingers.empty: #We assume no thumbs
return False
distances = []
palm_position = Geometry.to_vector(hand.palm_position)
for finger in hand.fingers: #Make a list of all distances from the center of the palm
finger_position = Geometry.to_vector(finger.tip_position)
difference = finger_position - palm_position
distances.append(difference.norm()) #Record the distance from the palm to the fingertip
average = sum(distances)/len(distances)
minimum = min(distances)
if average - minimum > 20: #Check if the finger closest to the palm is more than 20mm closer than the average distance
return True
else:
return False
示例5: finger_vectors_intersect
# 需要导入模块: import Geometry [as 别名]
# 或者: from Geometry import to_vector [as 别名]
def finger_vectors_intersect(finger1, finger2, vector_length, tolerance):
#Take Leap Finger objects and produce two line segment objects
finger_1_location = Geometry.to_vector(finger1.tip_position)
finger_1_direction = Geometry.to_vector(finger1.direction)
finger_1_vector = finger_1_direction.unit_vector() ** vector_length; #** is scalar mult
finger_1_endpoint = finger_1_vector + finger_1_location
finger_1_segment = Geometry.segment(finger_1_location, finger_1_endpoint)
finger_2_location = Geometry.to_vector(finger2.tip_position)
finger_2_direction = Geometry.to_vector(finger2.direction)
finger_2_vector = finger_2_direction.unit_vector() ** vector_length; #** is scalar mult
finger_2_endpoint = finger_2_vector + finger_2_location
finger_2_segment = Geometry.segment(finger_2_location, finger_2_endpoint)
minimum_distance = finger_1_segment.min_distance_finite(finger_2_segment)
if minimum_distance <= tolerance:
return True
return False
示例6: do_mouse_stuff
# 需要导入模块: import Geometry [as 别名]
# 或者: from Geometry import to_vector [as 别名]
def do_mouse_stuff(self, hand): # Take a hand and use it as a mouse
fingers = hand.fingers # The list of fingers on said hand
if not fingers.empty: # Make sure we have some fingers to work with
pointer_finger = self.select_pointer_finger(fingers) # Determine which finger to use
intersection = self.screen.intersect(
pointer_finger, True
) # Where the finger projection intersects with the screen
if not math.isnan(intersection.x) and not math.isnan(
intersection.y
): # If the finger intersects with the screen
x_coord = intersection.x * self.screen_resolution[0] # x pixel of intersection
y_coord = (1.0 - intersection.y) * self.screen_resolution[1] # y pixel of intersection
# print x_coord, y_coord #For debugging
self.cursor.move(x_coord, y_coord) # Move the cursor
if len(hand.fingers) == 2: # I changed clicking, so it can happen with two fingers
sorted_fingers = sort_fingers_left_to_right(
hand.fingers
) # Sorting fingers from left to right, so I can use my index finger for pointing. Sorry lefties!
finger1_pos = Geometry.to_vector(sorted_fingers[0].tip_position)
finger2_pos = Geometry.to_vector(sorted_fingers[1].tip_position)
difference = finger1_pos - finger2_pos
if (
difference.norm() > 40
and left_finger_still(sorted_fingers[0].tip_velocity.y)
and right_finger_moving(sorted_fingers[1].tip_velocity.y)
): # Check if the fingertips are a bit apart, the right finger is clicking down but the left finger is keeping still. This line prevents clicking while scrolling (or it should...)
self.mouse_button_debouncer.signal(
True
) # We have detected a possible click. The debouncer ensures that we don't have click jitter
else:
self.mouse_button_debouncer.signal(False) # Same idea as above (but opposite)
if (
self.cursor.left_button_pressed != self.mouse_button_debouncer.state
): # We need to push/unpush the cursor's button
# print "clicked:"
# print self.mouse_button_debouncer.state
self.cursor.set_left_button_pressed(
self.mouse_button_debouncer.state
) # Set the cursor to click/not click