File:Catenary properties.svg

Summary

Description
English: Diagram of a catenary showing some properties
Date
Source Own work
Author Vernanimalcula
SVG development
InfoField
 The SVG code is valid.
 This icon was created with Python.
Category:Valid SVG created with Python:Icons#Catenary%20properties.svg
 Category:Translation possible - SVGThis icon uses embedded text that can be easily translated using a text editor.

Licensing

Vernanimalcula, the copyright holder of this work, hereby publishes it under the following licenses:
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
Category:License migration redundant#Catenary%20properties.svgCategory:GFDL#Catenary%20properties.svg
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International, 3.0 Unported, 2.5 Generic, 2.0 Generic and 1.0 Generic license.
Attribution:
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Category:CC-BY-SA-4.0,3.0,2.5,2.0,1.0#Catenary%20properties.svg
You may select the license of your choice.
Category:Self-published work

Source code

The image is the output of this Python program:

from math import cosh, sinh

# Catenary
w = 400.0
a = 100.0
b = a*cosh((w/2)/a)
l = a*sinh((w/2)/a)
h = b-a

W, H = w+120, h+120 # total size of SVG image
ox, oy = 40.0, 40.0 # offset of diagram in SVG image (in SVG coords)

def x2svg( x ):
   """ Converts mathematial x to SVG coordinate """
   return ox + w/2 + x

def y2svg( y ):
   """ Converts mathematial y to SVG coordinate """
   return oy - y

def tosvg( t ):
   """ Converts t=(x,y,x,y,...) (mathematical) to SVG coordinates """
   coords = ()
   for i in range(0,len(t),2):
      coords = coords + (x2svg(t[i]),y2svg(t[i+1]))
   return coords

def print_polyline( t ):
   """ SVG polyline given by mathematical coordinates """
   ilist = ' '.join( ['%i'] * len(t) )
   s = '<polyline points="%s" style="stroke:#00A;stroke-width:3;fill:none;"/>' % ilist
   print s % tosvg(t)

fontsize=36
def print_text( x, y, txt, color='#00A' ):
   """ Print text centered at mathematical coordinates """
   svgx = x2svg(x) - 0.25*len(txt)*fontsize
   svgy = y2svg(y) + 0.25*fontsize
   print '<text x="%i" y="%i" style="font-family:sans-serif;font-size:%i;font-style:italic;color:%s">%s</text>' % (svgx,svgy,fontsize,color,txt)

def print_arrow( x0, y0, x1, y1, x2, y2, x3, y3 ):
   """ Print arrow with lines given by mathematical coordinates """
   print_polyline((x0,y0,x1,y1))
   print_polyline((x2,y2,x0,y0,x3,y3))

def print_xarrow( x0, y0, l, d ):
   """ Print horicontal arrow; l = long line; d = short line """
   print_arrow( x0, y0, x0+l, y0, x0+d, y0+d, x0+d, y0-d )

def print_yarrow( x0, y0, l, d ):
   """ Print vertical arrow; l = long line; d = short line """
   print_arrow( x0, y0, x0, y0+l, x0+d, y0+d, x0-d, y0+d )

########################################################################

print """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
     width="%i"
     height="%i"
     viewBox="%i %i %i %i">""" % (W,H,0,0,W,H)

# Background
print '<rect id="background" x="0" y="0" width="%i" height="%i" style="fill:#FFF"/>' % (W,H)
print '<rect id="curve" x="%i" y="%i" width="%i" height="%i" style="fill:#DDF"/>' % (ox,oy,w,h)

# Circle of radius a
print '<circle cx="%i" cy="%i" r="%i" style="stroke:#00A;stroke-width:3;fill:none;"/>' % (x2svg(0),y2svg(a-h),a)
print_polyline(( 0, a-h, a, a-h))
print_text( 0.5*a, 1.14*a-h, 'a' )

# Catenary
n = 100
xvals = [ w*(float(i)/n) for i in range(-n/2,n/2+1) ]
p = ' '.join([ '%i %i' % tosvg((x,a*cosh(x/a)-b)) for x in xvals ])
s = 'stroke:#000; stroke-width:5; fill:none'
print '<polyline points="%s" style="%s"/>' % (p,s)
print_text( -0.4*w, -0.1*h, 'l', color='#000' )

# Arrows
y0, l, d = 20, 0.44*w, 0.025*w
print_text( 0, y0, 'w' )
print_xarrow( -w/2, y0,  l,  d )
print_xarrow(  w/2, y0, -l, -d )
x0, l = -0.55*w, 0.42*h
print_text( x0, -h/2, 'h' )
print_yarrow(  x0,  0, -l, -d )
print_yarrow(  x0, -h,  l,  d )

# Labels
print_text( 0, -1.25*h, 'b=h+a' )
fontsize=18
y = -1.1*h
print_text( -w/2, y, 'x=-w/2' )
print_text(    0, y, 'x=0' )
print_text(  w/2, y, 'x=w/2' )
x = 0.6 * w
print_text( x, 0,  'y=0' )
print_text( x, -h, 'y=-h' )

print "</svg>"
Category:Catenary Category:Hyperbolic cosine function Category:Images with Python source code
Category:CC-BY-SA-4.0,3.0,2.5,2.0,1.0 Category:Catenary Category:GFDL Category:Hyperbolic cosine function Category:Images with Python source code Category:License migration redundant Category:Self-published work Category:Translation possible - SVG Category:Valid SVG created with Python:Icons