Even if this an old topic, i want to share a snipped of code i've done for the math. Maybe this will help someone stumble over this thread.
[code=python]
import math
def line_intersection(line1, line2):
xdiff = (line1[0][0] - line1[1][0], line2[0][0] - line2[1][0])
ydiff = (line1[0][1] - line1[1][1], line2[0][1] - line2[1][1])
def det(a, b):
return a[0] * b[1] - a[1] * b[0]
div = det(xdiff, ydiff)
if div == 0:
raise Exception('lines do not intersect')
d = (det(*line1), det(*line2))
x = det(d, xdiff) / div
y = det(d, ydiff) / div
return x, y
### Example ###
"""
G = (10, 30)
F = (11, 29)
E = (10, 10)
H = (11, 11)
line1 = [G, F]
line2 = [E, H]
print(line_intersection(line1, line2)) # -> (20, 20)
"""
def line_intersection_angle(vector_1, vector_2):
# vector_x = (x, y, angle_x)
# Define angles
angle_1 = vector_1[2]
angle_2 = vector_2[2]
# Create RV from angle between 0 and 2*pi
rv_1 = (math.cos(angle_1), -math.sin(angle_1))
rv_2 = (math.cos(angle_2), -math.sin(angle_2))
# Create virtual points to use line_intersection function
virtual_p1 = (vector_1[0]+rv_1[0], vector_1[1]+rv_1[1])
virtual_p2 = (vector_2[0]+rv_2[0], vector_2[1]+rv_2[1])
# Create lines for line_intersection function
line1 = ((vector_1[0], vector_1[1]), (virtual_p1[0], virtual_p1[1]))
line2 = ((vector_2[0], vector_2[1]), (virtual_p2[0], virtual_p2[1]))
return line_intersection(line1, line2)
### Example ###
"""
pos_1 = (10, 30)
angle_1 = 0.785 # pi/4 Arrow direction right-down (315°)
pos_2 = (10, 10)
angle_2 = 5.49 # (7/8)*pi Arrow direction right-up (45°)
print(get_energy_field_pos((pos_1[0], pos_1[1], angle_1), (pos_2[0], pos_2[1], angle_2))) # -> (~19.93, ~20.08)
"""
[/code]
The
recv from the packetlogger returns the angle of the arrow
in range 0 to 2*pi, where 0 is east, pi/2 is south and so on.
The pos is the position of the player from where you used the rod (obviously...)
The examples using the following scheme (geogebra screenshot):