I'm trying to make a heating cable layout for floor heating and i got stuck with this problem.
This i what i got from my code
So i made a small program asking for width,lenght of the room and calculating the are in m2. And i need a graphical representation of how cable should be on the floor. This is my code for arch:
# Add C-shaped curves at the end of each section
for i in range(int(width // spacing)):
theta = np.linspace(0, np.pi, 100)
x_curve = length + (spacing / 2) * np.cos(theta)
y_curve = (i + 1) * spacing + (spacing / 2) * np.sin(theta)
color = 'blue' if total_length < 5 else 'red'
ax.plot(x_curve, y_curve, color=color)
total_length += np.pi * (spacing / 2)
I'm a beginner so i tried what i knew so far. If someone can guide me or help me in anyway possible.
I'm trying to make a heating cable layout for floor heating and i got stuck with this problem.
This i what i got from my code
So i made a small program asking for width,lenght of the room and calculating the are in m2. And i need a graphical representation of how cable should be on the floor. This is my code for arch:
# Add C-shaped curves at the end of each section
for i in range(int(width // spacing)):
theta = np.linspace(0, np.pi, 100)
x_curve = length + (spacing / 2) * np.cos(theta)
y_curve = (i + 1) * spacing + (spacing / 2) * np.sin(theta)
color = 'blue' if total_length < 5 else 'red'
ax.plot(x_curve, y_curve, color=color)
total_length += np.pi * (spacing / 2)
I'm a beginner so i tried what i knew so far. If someone can guide me or help me in anyway possible.
I suspect you want to lay your cable like this.
The end arcs are essentially the same (so don't keep re-calculating them). Just shift them up at each crossing and alternate left and right sides.
import numpy as np
import matplotlib.pyplot as plt
width = 4
spacing = 0.25
N = 17
length = 4
total_length = 0
theta = np.linspace(0, np.pi, 100)
xarc = (spacing / 2) * np.sin(theta)
yarc = (spacing / 2) * ( 1 - np.cos(theta) )
base = 0
for i in range( N ):
color = 'blue' if total_length < 5 else 'red'
plt.plot( [0,length], [base,base], color=color) # draw line
if i == N - 1: break # no connector at end
if i % 2 == 0:
x_curve = length + xarc # arc on right
else:
x_curve = -xarc # arc on left
y_curve = base + yarc
plt.plot(x_curve, y_curve, color=color) # draw connector
base += spacing # update base and length
total_length += length + np.pi * (spacing / 2)
plt.show()
To properly connect the curves with the straight sections:
Rotate the curve by 90°: In your code, the curves are oriented incorrectly because the cosine and sine functions are seemingly swapped. To rotate them by 90°, switch your cosines of theta
to sines, and vice versa. Address the rotation matrix whenever you need an easy turn by 90° in whichever direction. In the code below, I changed the values of x_curve
and y_curve
to draw the curves as 'C's. You can remove the negative sign for x_curve
to achieve the reversed 'C's.
Position the centre correctly: I believe you want to connect the endpoints of the straight lines and so want the centres of the semicircles to be between each one, not at the ends. Use (i + 0.5)
(or + 1.5 depending on the necessary height) to set the height dynamically for the connection portions.
Here's the result:
for i in range(int(width // spacing)):
theta = np.linspace(0, np.pi, 100)
x_curve = length + (spacing / 2) * -np.sin(theta)
y_curve = (i + 0.5) * spacing + (spacing / 2) * np.cos(theta)