Skip to content

Instantly share code, notes, and snippets.

@CodeByAidan
Created September 6, 2024 19:02
Show Gist options
  • Save CodeByAidan/691fd11f4392e84c0cbed6bb911c3a51 to your computer and use it in GitHub Desktop.
Save CodeByAidan/691fd11f4392e84c0cbed6bb911c3a51 to your computer and use it in GitHub Desktop.
just some snippet IPython code to test lightning rod coverage, dimension of base, midpoint of base, on my minecraft base
In [1]: import math
In [2]: #given coordinates of the two corners
...: point_A = (-17.524, 61.000, 19.521)
...: point_B = (8.568, 61.000, -24.552)
In [3]: # Calculate the dimensions of the rectangle
...: length_x = abs(point_B[0] - point_A[0])
...: length_z = abs(point_B[2] - point_A[2])
In [4]: # Calculate the middle point
...: middle_point = (
...: (point_A[0] + point_B[0]) / 2,
...: (point_A[1] + point_B[1]) / 2,
...: (point_A[2] + point_B[2]) / 2,
...: )
In [5]: # Dimensions of the rectangle
...: rectangle_dimensions = (length_x, length_z)
In [6]: # Lightning Rod coverage
...: coverage_radius = 128
In [7]: # Check if the middle point covers the entire rectangle
...: def is_within_coverage(center, corners, radius):
...: for corner in corners:
...: distance = math.sqrt((center[0] - corner[0]) ** 2 + (center[2] - corner[2]) ** 2)
...: if distance > radius:
...: return False
...: return True
...:
In [8]: # Check corners
...: corners = [point_A, point_B]
In [9]: # Determine if the middle point covers all corners
...: covers = is_within_coverage(middle_point, corners, coverage_radius)
In [10]: # If not covered, find optimized point
...: optimized_point = middle_point
...: if not covers:
...: # Calculate optimized point by moving the middle point towards uncovered areas
...: if rectangle_dimensions[0] > 128:
...: # Adjust X coordinate
...: if point_A[0] < point_B[0]:
...: optimized_point = (middle_point[0] - (rectangle_dimensions[0] / 2 - coverage_radius), middle_point
...: [1], middle_point[2])
...: else:
...: optimized_point = (middle_point[0] + (rectangle_dimensions[0] / 2 - coverage_radius), middle_point
...: [1], middle_point[2])
...: if rectangle_dimensions[1] > 128:
...: # Adjust Z coordinate
...: if point_A[2] < point_B[2]:
...: optimized_point = (optimized_point[0], optimized_point[1], middle_point[2] - (rectangle_dimensions
...: [1] / 2 - coverage_radius))
...: else:
...: optimized_point = (optimized_point[0], optimized_point[1], middle_point[2] + (rectangle_dimensions
...: [1] / 2 - coverage_radius))
...:
In [11]: rectangle_dimensions, middle_point, covers, optimized_point
Out[11]:
((26.092, 44.073),
(-4.478000000000001, 61.0, -2.5154999999999994),
True,
(-4.478000000000001, 61.0, -2.5154999999999994))
In [12]:
@CodeByAidan
Copy link
Author

import math

# Given coordinates of the two corners
point_A = (-17.524, 61.000, 19.521)
point_B = (8.568, 61.000, -24.552)

# Calculate the dimensions of the rectangle
length_x = abs(point_B[0] - point_A[0])
length_z = abs(point_B[2] - point_A[2])

# Calculate the middle point
middle_point = (
    (point_A[0] + point_B[0]) / 2,
    (point_A[1] + point_B[1]) / 2,
    (point_A[2] + point_B[2]) / 2,
)

# Dimensions of the rectangle
rectangle_dimensions = (length_x, length_z)

# Lightning Rod coverage
coverage_radius = 128

# Check if the middle point covers the entire rectangle
def is_within_coverage(center, corners, radius):
    for corner in corners:
        distance = math.sqrt((center[0] - corner[0]) ** 2 + (center[2] - corner[2]) ** 2)
        if distance > radius:
            return False
    return True

# Check corners
corners = [point_A, point_B]

# Determine if the middle point covers all corners
covers = is_within_coverage(middle_point, corners, coverage_radius)

# If not covered, find optimized point
optimized_point = middle_point
if not covers:
    # Calculate optimized point by moving the middle point towards uncovered areas
    if rectangle_dimensions[0] > 128:
        # Adjust X coordinate
        if point_A[0] < point_B[0]:
            optimized_point = (middle_point[0] - (rectangle_dimensions[0] / 2 - coverage_radius), middle_point[1], middle_point[2])
        else:
            optimized_point = (middle_point[0] + (rectangle_dimensions[0] / 2 - coverage_radius), middle_point[1], middle_point[2])
    if rectangle_dimensions[1] > 128:
        # Adjust Z coordinate
        if point_A[2] < point_B[2]:
            optimized_point = (optimized_point[0], optimized_point[1], middle_point[2] - (rectangle_dimensions[1] / 2 - coverage_radius))
        else:
            optimized_point = (optimized_point[0], optimized_point[1], middle_point[2] + (rectangle_dimensions[1] / 2 - coverage_radius))

rectangle_dimensions, middle_point, covers, optimized_point

out:

((26.092, 44.073),
 (-4.478000000000001, 61.0, -2.5154999999999994),
 True,
 (-4.478000000000001, 61.0, -2.5154999999999994))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment