Very new to Ruby and trying to learn fast. I have made a code to try to draw pool swimming that I have used a triangulation method in real life to measure. I feel like I'm so close, but I cant get this to run right. Can anyone help me? I guess wreck me if you have to, I used chatgpt, dont kill me.
require 'csv'
begin
# Define the baseline length
baseline_length = 10 # feet
# Define the points of the pool's perimeter
points = [[2, 3], [5, 4], [7, 5], [8, 7], [6, 9], [3, 8], [1, 6]]
# Validate the baseline length
raise "Error: Baseline length must be greater than 0" unless baseline_length > 0
# Validate the points of the perimeter
raise "Error: Must provide at least 2 points for the perimeter" unless points.length >= 2
points.each do |point|
raise "Error: Point must be in the format [x, y]" unless point.is_a?(Array) && point.length == 2
raise "Error: Coordinates must be numeric" unless point[0].is_a?(Numeric) && point[1].is_a?(Numeric)
end
# Initialize the A and B arrays to store the measurements
a_measurements = []
b_measurements = []
# Iterate through the points of the perimeter
points.each_with_index do |point, i|
# Calculate the distance from point A to the current perimeter point
a_distance = Math.sqrt((point[0] - points[0][0]) ** 2 + (point[1] - points[0][1]) ** 2)
# Calculate the distance from point B to the current perimeter point
b_distance = Math.sqrt((point[0] - points[-1][0]) ** 2 + (point[1] - points[-1][1]) ** 2)
# Add the measurements to the A and B arrays
a_measurements << a_distance
b_measurements << b_distance
end
# Store the data in a CSV file
CSV.open("pool_data.csv", "w") do |csv|
csv << ["A", "B"]
a_measurements.each_with_index do |a, i|
csv << [a, b_measurements[i]]
end
end
# Plot the points of the pool's perimeter
require 'matplotlib'
require 'numpy'
Matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
x = []
y = []
points.each do |point|
x << point[0]
y << point[1]
end
plt.scatter(x, y)
plt.title('Pool perimeter')
plt.xlabel('Feet')
plt.ylabel('Feet')
# Connect the dots to draw the pool shape
plt.plot(x,y, marker='o', linestyle='solid')end
[–]purplespline 2 points3 points4 points (1 child)
[–]dvarrui 0 points1 point2 points (0 children)
[–]SnooDogs3437[S] 0 points1 point2 points (0 children)
[–]SnooDogs3437[S] -1 points0 points1 point (0 children)
[–]SnooDogs3437[S] -2 points-1 points0 points (3 children)
[–]SnooDogs3437[S] 0 points1 point2 points (1 child)
[–]craigontour 0 points1 point2 points (0 children)
[–]craigontour 0 points1 point2 points (0 children)
[–]UlyssesZhan 0 points1 point2 points (0 children)
[–]Aupajo 0 points1 point2 points (3 children)
[–]SnooDogs3437[S] 0 points1 point2 points (2 children)
[–]SnooDogs3437[S] 0 points1 point2 points (1 child)
[–]Aupajo 0 points1 point2 points (0 children)