full implementation of generate_coord_list_fixed_angle
This commit is contained in:
parent
69c10571ba
commit
6e1ea0fd8b
@ -644,9 +644,44 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float,
|
||||
np.savetxt("Wavelength.txt", wl)
|
||||
np.savetxt("B_Values.txt", bval_lst)
|
||||
|
||||
def generate_coord_list_fixed_angle(angle, b_abs, b_abs_step_size):
|
||||
# TODO: write a function that returns a list of coordinates (x,y) for a fixed angle and a given b_val, b_val_step_size
|
||||
pass
|
||||
def generate_coord_list_fixed_angle(angle, b_val, b_val_step_size, reverse=False):
|
||||
"""
|
||||
Generates a list of (x, y) Cartesian coordinates along a line defined by a fixed angle,
|
||||
scanning from -b_val to b_val or from b_val to -b_val depending on the reverse flag.
|
||||
|
||||
Args:
|
||||
angle (float): The fixed angle (in degrees) from the positive x-axis.
|
||||
b_val (float): The maximum distance from the origin (both positive and negative).
|
||||
b_val_step_size (float): The increment in distance for each point.
|
||||
reverse (bool): If True, scan from b_val to -b_val. If False, scan from -b_val to b_val.
|
||||
|
||||
Returns:
|
||||
list: A list of tuples representing Cartesian coordinates (x, y).
|
||||
"""
|
||||
coordinates = []
|
||||
|
||||
# Convert angle from degrees to radians
|
||||
angle_rad = math.radians(angle)
|
||||
|
||||
# Determine the scan direction based on the reverse flag
|
||||
if reverse:
|
||||
# Scan from b_val to -b_val
|
||||
current_b = b_val
|
||||
while current_b >= -b_val:
|
||||
x = current_b * math.cos(angle_rad)
|
||||
y = current_b * math.sin(angle_rad)
|
||||
coordinates.append((x, y))
|
||||
current_b -= b_val_step_size
|
||||
else:
|
||||
# Scan from -b_val to b_val
|
||||
current_b = -b_val
|
||||
while current_b <= b_val:
|
||||
x = current_b * math.cos(angle_rad)
|
||||
y = current_b * math.sin(angle_rad)
|
||||
coordinates.append((x, y))
|
||||
current_b += b_val_step_size
|
||||
|
||||
return coordinates
|
||||
|
||||
def generate_angle_coord_list(radius, start_angle, end_angle, step_size, clockwise=True):
|
||||
# TODO: DOCS
|
||||
|
44
Test.py
44
Test.py
@ -76,6 +76,45 @@ def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True
|
||||
|
||||
return [angles, coordinates]
|
||||
|
||||
def generate_coord_list_fixed_angle(angle, b_val, b_val_step_size, reverse=False):
|
||||
"""
|
||||
Generates a list of (x, y) Cartesian coordinates along a line defined by a fixed angle,
|
||||
scanning from -b_val to b_val or from b_val to -b_val depending on the reverse flag.
|
||||
|
||||
Args:
|
||||
angle (float): The fixed angle (in degrees) from the positive x-axis.
|
||||
b_val (float): The maximum distance from the origin (both positive and negative).
|
||||
b_val_step_size (float): The increment in distance for each point.
|
||||
reverse (bool): If True, scan from b_val to -b_val. If False, scan from -b_val to b_val.
|
||||
|
||||
Returns:
|
||||
list: A list of tuples representing Cartesian coordinates (x, y).
|
||||
"""
|
||||
coordinates = []
|
||||
|
||||
# Convert angle from degrees to radians
|
||||
angle_rad = math.radians(angle)
|
||||
|
||||
# Determine the scan direction based on the reverse flag
|
||||
if reverse:
|
||||
# Scan from b_val to -b_val
|
||||
current_b = b_val
|
||||
while current_b >= -b_val:
|
||||
x = current_b * math.cos(angle_rad)
|
||||
y = current_b * math.sin(angle_rad)
|
||||
coordinates.append((x, y))
|
||||
current_b -= b_val_step_size
|
||||
else:
|
||||
# Scan from -b_val to b_val
|
||||
current_b = -b_val
|
||||
while current_b <= b_val:
|
||||
x = current_b * math.cos(angle_rad)
|
||||
y = current_b * math.sin(angle_rad)
|
||||
coordinates.append((x, y))
|
||||
current_b += b_val_step_size
|
||||
|
||||
return coordinates
|
||||
|
||||
if __name__=="__main__":
|
||||
# Example usage
|
||||
radius = 5
|
||||
@ -86,4 +125,7 @@ if __name__=="__main__":
|
||||
angles, coordinates = polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True)
|
||||
|
||||
print('\n', "Angles:", angles, '\n')
|
||||
print("Coordinates:", coordinates, '\n',)
|
||||
print("Coordinates:", coordinates, '\n',)
|
||||
|
||||
print(generate_coord_list_fixed_angle(10, 5, 1, reverse=False))
|
||||
|
Loading…
x
Reference in New Issue
Block a user