You are on page 1of 2

If the angle of incidence is greater than 90 degrees, it means that the object

is on the opposite side of the light source. In this case, you can modify the
code to calculate the angle of incidence as 180 - angle_of_incidence
instead of using 90 - abs(latitude) + np.cos(np.radians(day_of_year)) * 23.5.
Here's the updated code:
python
Copy
import matplotlib.pyplot as plt
import numpy as np

# Calculate the angle of incidence based on latitude and date


def calculate_angle_of_incidence(latitude, day_of_year):
angle_of_incidence = 90 - abs(latitude) +
np.cos(np.radians(day_of_year)) * 23.5
if angle_of_incidence > 90:
angle_of_incidence = 180 - angle_of_incidence
return angle_of_incidence

# Calculate the shadow length


def calculate_shadow_length(object_size, angle_of_incidence):
shadow_length = object_size /
np.tan(np.radians(angle_of_incidence))
return abs(shadow_length) # Convert negative shadow lengths to
positive

# Get user input


latitude = float(input("Enter the latitude (in degrees): "))
object_size = float(input("Enter the size of the object (in meters):
"))

# Define the days of the year


days_of_year = np.linspace(90, 449, 360)

# Calculate the angle of incidence and shadow lengths for each day of
the year
angles_of_incidence = [calculate_angle_of_incidence(latitude, day) for
day in days_of_year]
shadow_lengths = [calculate_shadow_length(object_size, angle) for angle
in angles_of_incidence]

# Plot the graph


fig, ax1 = plt.subplots()

# Plot shadow lengths


ax1.plot(days_of_year, shadow_lengths, color='tab:blue')
ax1.set_xlabel('Day of the Year')
ax1.set_ylabel('Shadow Length (m)', color='tab:blue')
ax1.tick_params(axis='y', labelcolor='tab:blue')
# Create a twin axis for angle of incidence
ax2 = ax1.twinx()
ax2.plot(days_of_year, angles_of_incidence, color='tab:red')
ax2.set_ylabel('Angle of Incidence', color='tab:red')
ax2.tick_params(axis='y', labelcolor='tab:red')

# Set title and grid


plt.title('Change in Shadow Length and Angle of Incidence throughout
the Year')
plt.grid(True)

# Show the plot


plt.show()

With this modification, if the calculated angle of incidence is greater than


90 degrees, it will be adjusted to 180 - angle_of_incidence.

You might also like