⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀         ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.2 KiB

  1. import plotly.graph_objects as go
  2. import numpy as np
  3. # Define the curvature function
  4. def kappa(x):
  5. return (1-((-((-1)**np.floor(x/np.pi*2)*(np.exp(-1/((x/np.pi*2)-np.floor((x/np.pi*2))))
  6. /(np.exp(-1/((x/np.pi*2)-np.floor((x/np.pi*2))))+np.exp(-1/(1-(x/np.pi*2)+np.floor((x/np.pi*2))))))) +
  7. ((-1)**np.floor((x/np.pi*2)/1)*(np.exp(-1/(1-(x/np.pi*2)+np.floor((x/np.pi*2))))/(np.exp(-1/((x/np.pi*2)-
  8. np.floor((x/np.pi*2))))+np.exp(-1/(1-(x/np.pi*2)+np.floor((x/np.pi*2))))))))/2 + .5))
  9. # Generate x values
  10. x_vals = np.linspace(0, 4*np.pi, 1000)
  11. # Compute kappa values
  12. kappa_vals = kappa(x_vals)
  13. # Integrate kappa values to get theta values (angles)
  14. theta_vals = np.cumsum(kappa_vals) * (x_vals[1]-x_vals[0])
  15. # Compute x and y coordinates of the curve
  16. x_coords = np.cumsum(np.cos(theta_vals)) * (x_vals[1]-x_vals[0])
  17. y_coords = np.cumsum(np.sin(theta_vals)) * (x_vals[1]-x_vals[0])
  18. # Create a plot using plotly
  19. fig = go.Figure()
  20. # Add line to the figure for the curve
  21. fig.add_trace(go.Scatter(x=x_coords, y=y_coords, mode='lines', name='Curve'))
  22. # Update layout
  23. fig.update_layout(
  24. autosize=True,
  25. xaxis=dict(scaleanchor='y', scaleratio=1) # this line sets the aspect ratio
  26. )
  27. fig.show()