search_index.json 53 KB

1
  1. {"config":{"lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"Welcome to Jupyter Sketcher User Guide Home Page of jupytersketcher project Any time you need to make a sketch while solving a mechanical problem with a jupyter notebook, then PySketcher is your friend! A sketch capturing the \"dry friction case\" How it is structured: the composition hierarchy","title":"Home"},{"location":"#welcome-to-jupyter-sketcher-user-guide","text":"Home Page of jupytersketcher project Any time you need to make a sketch while solving a mechanical problem with a jupyter notebook, then PySketcher is your friend! A sketch capturing the \"dry friction case\" How it is structured: the composition hierarchy","title":"Welcome to Jupyter Sketcher User Guide"},{"location":"about/","text":"In summer 2020 I discovered Pysketcher as I was looking for a way to create Physics sketches for both design and simulation. My second requirement is to have sketches available in Jupyter notebooks (Lab or notebook server) Pysketch was developped in 2012 by Hans Petter Langtangen , see it in GitHub . At that time, Jupyter was emerging and Pysketch was developped as a standalone application. I just need to upgrade it to make it compatible with Jupyter: This is the inception of Jupyter Sketch project! Documentation Built with mkdocs 1.1.0 mkdocs-material 5.4.0","title":"About"},{"location":"gallerydoc/","text":"Dry Friction Car Pendulum Dry Friction Car Pendulum Spring Mass Spring Dashpot Mass Jet pump Spring Spring Dashpot Jet pump","title":"Gallery"},{"location":"learningbyexample/","text":"A language to describe a sketch Pysketcher initial version HPL Pysketcher enable sketch definition in python. HPL is showing the hierachical nature of sketches. This is implemented via the Composition function. One can further grasp this using the graphviz_dot function applied to discover the composition herarchy implemented as a graphviz image see The hierarchy of the \"friction\" sketch at the end of this page. Due to the hierarchical nature of sketches, it is quite straightforward to think about using yaml as the syntax for defining a sketch. Benefits are the following: Leaner sketch writing as only data relevant to the context needs to be defined A more straightforward reading for the same reason A more robust sketch definition The same set of rules is applied to generate a sketch No further python idiom is be intermingled as opposed to the case of python defined sketches Don't make me wrong! Data defined versus program defined there is no winner, it's just a matter of context Example This example provides the yaml content to define the Dry Friction case The final sketch An inclined plan (the A-B edge) supports a blue rectangle which is dragged down by gravity. The plan makes an angle \\theta \\theta with the ground level. Sketch implementation notebook includes a controller enabling the \\theta \\theta angle to change. The whole plan, including the body, can rotate arround point B. Support files The example we are developing now is based upon the \"Dry Friction mockup\" notebook the rendered html version of the notbook can be viewed here the notebook can be download here The yaml definition Sketcher language is defined as a yaml compliant file or string. The yaml file is a dictionnary of \"objects\". Objects can be regular python objects or sketcher objects. A skertcher object is composed as follow: a formula : it's a leaf object, like Rectangle, Circle, Line etc or a composition a style list : line or fill colors, line stroke... declared as a yaml hierarchy a transformation list : the defined object can be transformed using sketcher transformation: translation, rotation... As a general rule, a new object suppose all parameters to be defined before they are used to construct it. For example, you can create a circle if the center and the radius have been defined earlier in the file. The general layout of a sketcher file is as follow: Libraries, Construction Variables, Frame declaration of the libraries used by the objects further declared: at least pysketcher is mandatory various global variable which encompass the \"Construction\" variables which define the object main physical dimensions, positions... some \"actions\" corresponding to executable python sentences One mandatory action is the setting of the drawing frame (drawing_tool.set_coordinate_system): it must be declared before any other pysketcher object is used. Other use case of action is the setting of global parameters like default line color: (drawing_tool.set_linecolor('black')) for example this is stored in the head string thereafter The example uses the following objects libraries: setting the libraries used for this sketch constants: all the sketch dimensionning data frame: all the shapes or geometric objects which will be used by the other shapes Sketcher Objects Usually starting with the declaration of Pysketcher leaf objects (Geometry object like Line, Circle, Rectangle...) May be aggregated using the composition object Composition can be made of composition object (recursive behaviour) Grouping leafs and composition will be further used to apply transformation latter on (based on the \"physics\") The example uese three group of shapes The body object The plan object The friction main object The plan includes the body The friction includes the plan (that will be able to rotate as a group) and the ground (will stay fixed) Libraries libraries = \"\"\"\\ name: head shapes: libraries: [\"from math import tan, radians, sin, cos\",\"from pysketcher import *\"] \"\"\" Constants: Construction parameters constants = \"\"\"\\ name: constants shapes: fontsize: 18 # size of the characters g: 9.81 # constant gravity theta: 30.0 # inclined plane angle L: 10.0 # sketch sizing parameter a: 1.0 # xmin: 0.0 # sketech min Abscissa ymin: -3.0 # sketech min Ordinate rl: 2.0 # rectangle width rL: 1.0 # rectangle length \"\"\" Frame: core geometric parameters frame = \"\"\"\\ name: frame shapes: setframe: # sketch setup action: \"drawing_tool.set_coordinate_system(xmin=xmin-L/5, xmax=xmin+1.5*L,ymin=ymin, ymax=ymin+1.5*L,instruction_file='tmp_mpl_friction.py')\" setblackline: # default frame values and actions action: \"drawing_tool.set_linecolor('black')\" B: point(a+L,0) # wall right end A: point(a,tan(radians(theta))*L) # wall left end normal_vec: point(sin(radians(theta)),cos(radians(theta))) # Vector normal to wall tangent_vec: point(cos(radians(theta)),-sin(radians(theta))) # Vector tangent to wall help_line: Line(A,B) # wall line x: a + 3*L/10. # contact point Abscissa y: help_line(x=x) # contact point Ordinate contact: point(x, y) # contact point: middle of the rectangle bottom edge c: contact + rL/2*normal_vec \"\"\" The body object body = \"\"\"\\ name: body shapes: rectangle: formula: Rectangle(contact, rl, rL) style: linecolor: blue filled_curves: blue transform: [\"rotate(-theta, contact)\", \"translate(-rl/2*tangent_vec)\"] N: formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start') style: linecolor: black wheel: formula: \"Composition({'outer': rectangle})\" style: shadow: 1 mc: formula: Text(r'$c$', c) body: formula: \"Composition({'wheel': wheel, 'N': N, 'mc': mc})\" style: linecolor: black \"\"\" The plan object plan = \"\"\"\\ name: plan shapes: mB: formula: Text(r'$B$',B) mA: formula: Text(r'$A$', A) wall: formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False) style: linecolor: black x_const: formula: Line(contact, contact + point(0,4)) style: linestyle: dotted transform: rotate(-theta, contact) x_axis: formula: \"Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta)\" plan: formula: \"Composition({'body': body, 'inclined wall': wall, 'x start': x_const, 'x axis': x_axis, 'mA': mA, 'mB': mB})\" \"\"\" The friction sketch friction = \"\"\"\\ name: friction shapes: mg: formula: Gravity(c, rl, text='$Mg$') style: linecolor: black angle: formula: \"Arc_wText(r'$<bslash>theta$', center=B, radius=3, start_angle=180-theta, arc_angle=theta, fontsize=fontsize)\" style: linecolor: black linewidth: 1 ground: formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0)) stlye: linecolor: black linestyle: dashed linewidth: 1 friction: formula: \"Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle': angle})\" \"\"\" Using the parser To parse the above example, the following code do the job. libraries, constants and frame must be used first as all the other bits needs one or more variable they defines. After, any other sketch can be parsed, the order just need to respect precedence (if one object uses another it must be parsed after) this setting allows naturally a modular definition of sketch objects The parser checks for syntax precedence and warns of any detected error. myfig = {} if sketchParse(libraries,myfig): if sketchParse(constants,myfig): if sketchParse(frame,myfig): if sketchParse(body,myfig): if sketchParse(plan,myfig): if sketchParse(friction,myfig): print(\"success\") \"friction\" sketch hierarchy","title":"Learning by Example"},{"location":"learningbyexample/#a-language-to-describe-a-sketch","text":"Pysketcher initial version HPL Pysketcher enable sketch definition in python. HPL is showing the hierachical nature of sketches. This is implemented via the Composition function. One can further grasp this using the graphviz_dot function applied to discover the composition herarchy implemented as a graphviz image see The hierarchy of the \"friction\" sketch at the end of this page. Due to the hierarchical nature of sketches, it is quite straightforward to think about using yaml as the syntax for defining a sketch. Benefits are the following: Leaner sketch writing as only data relevant to the context needs to be defined A more straightforward reading for the same reason A more robust sketch definition The same set of rules is applied to generate a sketch No further python idiom is be intermingled as opposed to the case of python defined sketches Don't make me wrong! Data defined versus program defined there is no winner, it's just a matter of context","title":"A language to describe a sketch"},{"location":"learningbyexample/#example","text":"This example provides the yaml content to define the Dry Friction case","title":"Example"},{"location":"learningbyexample/#the-final-sketch","text":"An inclined plan (the A-B edge) supports a blue rectangle which is dragged down by gravity. The plan makes an angle \\theta \\theta with the ground level. Sketch implementation notebook includes a controller enabling the \\theta \\theta angle to change. The whole plan, including the body, can rotate arround point B.","title":"The final sketch"},{"location":"learningbyexample/#support-files","text":"The example we are developing now is based upon the \"Dry Friction mockup\" notebook the rendered html version of the notbook can be viewed here the notebook can be download here","title":"Support files"},{"location":"learningbyexample/#the-yaml-definition","text":"Sketcher language is defined as a yaml compliant file or string. The yaml file is a dictionnary of \"objects\". Objects can be regular python objects or sketcher objects. A skertcher object is composed as follow: a formula : it's a leaf object, like Rectangle, Circle, Line etc or a composition a style list : line or fill colors, line stroke... declared as a yaml hierarchy a transformation list : the defined object can be transformed using sketcher transformation: translation, rotation... As a general rule, a new object suppose all parameters to be defined before they are used to construct it. For example, you can create a circle if the center and the radius have been defined earlier in the file. The general layout of a sketcher file is as follow: Libraries, Construction Variables, Frame declaration of the libraries used by the objects further declared: at least pysketcher is mandatory various global variable which encompass the \"Construction\" variables which define the object main physical dimensions, positions... some \"actions\" corresponding to executable python sentences One mandatory action is the setting of the drawing frame (drawing_tool.set_coordinate_system): it must be declared before any other pysketcher object is used. Other use case of action is the setting of global parameters like default line color: (drawing_tool.set_linecolor('black')) for example this is stored in the head string thereafter The example uses the following objects libraries: setting the libraries used for this sketch constants: all the sketch dimensionning data frame: all the shapes or geometric objects which will be used by the other shapes Sketcher Objects Usually starting with the declaration of Pysketcher leaf objects (Geometry object like Line, Circle, Rectangle...) May be aggregated using the composition object Composition can be made of composition object (recursive behaviour) Grouping leafs and composition will be further used to apply transformation latter on (based on the \"physics\") The example uese three group of shapes The body object The plan object The friction main object The plan includes the body The friction includes the plan (that will be able to rotate as a group) and the ground (will stay fixed)","title":"The yaml definition"},{"location":"learningbyexample/#libraries","text":"libraries = \"\"\"\\ name: head shapes: libraries: [\"from math import tan, radians, sin, cos\",\"from pysketcher import *\"] \"\"\"","title":"Libraries"},{"location":"learningbyexample/#constants-construction-parameters","text":"constants = \"\"\"\\ name: constants shapes: fontsize: 18 # size of the characters g: 9.81 # constant gravity theta: 30.0 # inclined plane angle L: 10.0 # sketch sizing parameter a: 1.0 # xmin: 0.0 # sketech min Abscissa ymin: -3.0 # sketech min Ordinate rl: 2.0 # rectangle width rL: 1.0 # rectangle length \"\"\"","title":"Constants: Construction parameters"},{"location":"learningbyexample/#frame-core-geometric-parameters","text":"frame = \"\"\"\\ name: frame shapes: setframe: # sketch setup action: \"drawing_tool.set_coordinate_system(xmin=xmin-L/5, xmax=xmin+1.5*L,ymin=ymin, ymax=ymin+1.5*L,instruction_file='tmp_mpl_friction.py')\" setblackline: # default frame values and actions action: \"drawing_tool.set_linecolor('black')\" B: point(a+L,0) # wall right end A: point(a,tan(radians(theta))*L) # wall left end normal_vec: point(sin(radians(theta)),cos(radians(theta))) # Vector normal to wall tangent_vec: point(cos(radians(theta)),-sin(radians(theta))) # Vector tangent to wall help_line: Line(A,B) # wall line x: a + 3*L/10. # contact point Abscissa y: help_line(x=x) # contact point Ordinate contact: point(x, y) # contact point: middle of the rectangle bottom edge c: contact + rL/2*normal_vec \"\"\"","title":"Frame: core geometric parameters"},{"location":"learningbyexample/#the-body-object","text":"body = \"\"\"\\ name: body shapes: rectangle: formula: Rectangle(contact, rl, rL) style: linecolor: blue filled_curves: blue transform: [\"rotate(-theta, contact)\", \"translate(-rl/2*tangent_vec)\"] N: formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start') style: linecolor: black wheel: formula: \"Composition({'outer': rectangle})\" style: shadow: 1 mc: formula: Text(r'$c$', c) body: formula: \"Composition({'wheel': wheel, 'N': N, 'mc': mc})\" style: linecolor: black \"\"\"","title":"The body object"},{"location":"learningbyexample/#the-plan-object","text":"plan = \"\"\"\\ name: plan shapes: mB: formula: Text(r'$B$',B) mA: formula: Text(r'$A$', A) wall: formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False) style: linecolor: black x_const: formula: Line(contact, contact + point(0,4)) style: linestyle: dotted transform: rotate(-theta, contact) x_axis: formula: \"Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta)\" plan: formula: \"Composition({'body': body, 'inclined wall': wall, 'x start': x_const, 'x axis': x_axis, 'mA': mA, 'mB': mB})\" \"\"\"","title":"The plan object"},{"location":"learningbyexample/#the-friction-sketch","text":"friction = \"\"\"\\ name: friction shapes: mg: formula: Gravity(c, rl, text='$Mg$') style: linecolor: black angle: formula: \"Arc_wText(r'$<bslash>theta$', center=B, radius=3, start_angle=180-theta, arc_angle=theta, fontsize=fontsize)\" style: linecolor: black linewidth: 1 ground: formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0)) stlye: linecolor: black linestyle: dashed linewidth: 1 friction: formula: \"Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle': angle})\" \"\"\"","title":"The friction sketch"},{"location":"learningbyexample/#using-the-parser","text":"To parse the above example, the following code do the job. libraries, constants and frame must be used first as all the other bits needs one or more variable they defines. After, any other sketch can be parsed, the order just need to respect precedence (if one object uses another it must be parsed after) this setting allows naturally a modular definition of sketch objects The parser checks for syntax precedence and warns of any detected error. myfig = {} if sketchParse(libraries,myfig): if sketchParse(constants,myfig): if sketchParse(frame,myfig): if sketchParse(body,myfig): if sketchParse(plan,myfig): if sketchParse(friction,myfig): print(\"success\")","title":"Using the parser"},{"location":"learningbyexample/#friction-sketch-hierarchy","text":"","title":"\"friction\" sketch hierarchy"},{"location":"presentation/","text":"Problem solved When you need to address a mechanical design problem, sooner or later you are going to sketch a figure to capture problem's parameters and variables. The better documented, the easier the problem is to resolve for the designer, and the easier it is for others to understand how it is actually solved. What if you could capture this in the program solving the problem and use it as a repository for all definitions and physical variables? This is what jupytersketcher (name of pysketcher module) is proposing to solve. Of course, this makes even more sense when using Jupyter notebooks, because as a sketch not only the image of the solved problem can be displayed, but the dictionary of all variables processed in the notebook for solving physics is used to draw the image and at the same time to solve the equations of motion. jupytersketcher is another small step to help building reusable science. Getting Started You can use the binder link in jupytersketcher Github to make some experiments with pysketcher. pysketcher features Drawing sketches on a matplotlib widget for Jupyter Notebook server or Lab Defining a yaml based \"grammar\" to define sketches and simplify reuse Animating sketches within Jupyter notebooks Main benefit With Pysketcher for Jupyter mechanical notebooks, you get a single copy of the description of the problem which is as well a space to solve the system physics and display how it works","title":"Presentation"},{"location":"presentation/#problem-solved","text":"When you need to address a mechanical design problem, sooner or later you are going to sketch a figure to capture problem's parameters and variables. The better documented, the easier the problem is to resolve for the designer, and the easier it is for others to understand how it is actually solved. What if you could capture this in the program solving the problem and use it as a repository for all definitions and physical variables? This is what jupytersketcher (name of pysketcher module) is proposing to solve. Of course, this makes even more sense when using Jupyter notebooks, because as a sketch not only the image of the solved problem can be displayed, but the dictionary of all variables processed in the notebook for solving physics is used to draw the image and at the same time to solve the equations of motion. jupytersketcher is another small step to help building reusable science.","title":"Problem solved"},{"location":"presentation/#getting-started","text":"You can use the binder link in jupytersketcher Github to make some experiments with pysketcher.","title":"Getting Started"},{"location":"presentation/#pysketcher-features","text":"Drawing sketches on a matplotlib widget for Jupyter Notebook server or Lab Defining a yaml based \"grammar\" to define sketches and simplify reuse Animating sketches within Jupyter notebooks","title":"pysketcher features"},{"location":"presentation/#main-benefit","text":"With Pysketcher for Jupyter mechanical notebooks, you get a single copy of the description of the problem which is as well a space to solve the system physics and display how it works","title":"Main benefit"},{"location":"shapereference/","text":"List of Shapes Code to display shapes Line : defines a line providing start and end point Rectangle : defines a rectangle providing bottom left corner, x dimension, y dimension Triangle : defines a triangle providing three corner Circle : defines a circle proving center and radius Distance with text : defines a sizing mark with a label Text : defines a given text positionned at the provided point Cross : defines a cross positionned at the provided point Axis : defines an axis at the given point with a given label Arc : defines an Arc providing a center point, a radius, a starting angle and an angle (rotates clock-wise) Arc_wText : defines an arc with text positionned left (moving clock-wise) of arc half-way Arrow1 : defines a line with arrow(s) given starting and ending point and arrow termination(s) ->, \\<->, \\<- Force : defines an Indication of a force by an arrow and a text (symbol) Wall : defines an hached box given starting, ending point and thickness, filled with a pattern Curve : defines a general curve as a sequence of (x,y) coordinates Trajectory : defines a general curve as a sequence of Point (subclass Curve) Gravity : defines a downward-pointing gravity arrow with the symbol g or user given symbol. Moment : defines a Moment arrow with text given text, center and radius Text_wArrow : defines Text, but an arrow is drawn from the mid part of the text to some point arrow_tip Wheel : defines Hub and spokes Wheel given center, radius, spokes (default 10), inner_radius(default 1/5 of radius) Spring : defines a vertical spring, starting at start and with length as total vertical length Dashpot : defines a vertical dashpot of height total_length and start as bottom/starting point. Line home Defines a line providing start and end point Yaml name: line shapes: A: point(-5,-5) B: point(5,5) line: Line(A,B) Python A = point(-5,-5) B = point(5,5) line = Line(A,B) line.set_name(\"line\") Rectangle home Defines a rectangle providing bottom left corner, x dimension, y dimension Yaml name: rectangle shapes: L: 8 h: 5 p: point(-(L/2),-(h/2)) rectangle: Rectangle(p,L,h) Python L = 8 h = 5 p = point(-(L/2),-(h/2)) rectangle = Rectangle(p,L,h) rectangle.set_name(\"rectangle\") Circle home Defines a circle proving center and radius Yaml name: circle shapes: circle: Circle(point(0,0),5) Python circle = Circle(point(0,0),5) circle.set_name(\"circle\") Triangle home Defines a triangle providing three corner Yaml name: triangle shapes: L: 3.0 W: 4.0 triangle: Triangle(p1=(W/2,0), p2=(3*W/2,W/2), p3=(4*W/5.,L)) Python L = 3.0 W = 4.0 triangle = Triangle(p1=(W/2,0), p2=(3*W/2,W/2), p3=(4*W/5.,L)) triangle.set_name(\"triangle\") Distance with text home Defines a sizing mark with a label Yaml name: dwt shapes: fontsize: 14 t: r'$ 2\\pi R^2 $' # sample text dwt: Distance_wText((-4,0), (8, 5), t, fontsize) Python fontsize=14 t = r'$ 2\\pi R^2 $' # sample text dwt = Distance_wText((-4,0), (8, 5), t, fontsize) dwt.set_name(\"dwt\") Text home Defines a given text positionned at the provided point Yaml name: text shapes: text: Text(r'$c$', point(0,0)) Python text = Text(r'$c$', point(0,0)) text.set_name(\"text\") Cross home Defines a cross positionned at the provided point Yaml name: cross shapes: cross: Cross(point(0,0)) Python cross = Cross(point(1,0)) cross.set_name(\"cross\") Axis home Defines an axis at the given point with a given label Yaml name: axis shapes: axis: Axis((0,0), 5, 'x', rotation_angle=0) Python axis = Axis((0,0), 5, 'x', rotation_angle=0) axis.set_name(\"axis\") Arc home Defines an Arc providing a center point, a radius, a starting angle and an angle (rotates clock-wise) Yaml name: arc shapes: center: point(0,0) radius: 1 angle: 120 start_angle: 180-angle arc_angle: angle arc: Arc(center, radius, start_angle, arc_angle) Python center = point(0,0) radius = 1 angle = 120 start_angle = 180-angle arc_angle = angle arc = Arc(center, radius, start_angle, arc_angle) arc.set_name(\"arc\") Arc_wText home Defines an arc with text positionned left (moving clock-wise) of arc half-way Yaml name: arc_wtxt shapes: center: point(0,0) radius: 1 angle: 120 start_angle: 180-angle arc_angle: angle arc_wtxt: \"Arc_wText(r'$<bslash>theta$', center, radius, start_angle, arc_angle)\" Python center = point(0,0) radius = 1 angle = 120 start_angle = 180-angle arc_angle = angle arc_wtxt = Arc_wText(r'$\\theta$', center, radius, start_angle, arc_angle) arc_wtxt.set_name(\"arcwtxt\") Arrow1 home defines a line with arrow(s) given starting and ending point and arrow termination(s) ->, \\<->, \\<- Yaml name: arrow1 shapes: start: point(0,0) end: point(5,5) arrow1: Arrow1(start, end, style='<->') Python start = point(0,0) end = point(5,5) arrow1 = Arrow1(start, end, style='<->') arrow1.set_name(\"arrow1\") Force home defines an Indication of a force by an arrow and a text (symbol) Yaml name: force shapes: x: 0 y: 0 contact: point(x, y) vector: point(-3,-5) force: Force(contact - vector, contact, r'$Force$', text_pos='start') Python x = 0 y = 0 contact = point(x, y) vector = point(-3,-5) force = Force(contact - vector, contact, r'$Force$', text_pos='start') force.set_name(\"force\") Wall home defines an hached box given starting, ending point and thickness, filled with a pattern Yaml name: wall shapes: theta: 30 L: 8 B: point(L-4,-2) # wall right end A: point(-4,tan(radians(theta))*L-2) # wall left end wall: formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.5,transparent=False) style: linecolor: black Python theta = 30 L = 8 B = point(L-4,-2) # wall right end A = point(-4,tan(radians(theta))*L-2) # wall left end wall= Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.5,transparent=False) wall.set_linecolor('black') wall.set_name(\"wall\") Curve home defines a general curve as a sequence of (x,y) coordinates Yaml curve=\"\"\"\\ name: curve shapes: N: 100 x: np.linspace(-2.0, 2.0, N) y: x**3 curve: Curve(x,y) \"\"\" Python N = 100 x = np.linspace(-2.0, 2.0, N) y = x**3 curve = Curve(x,y) curve.draw() curve.set_name(\"curve\") Trajectory home defines a general curve as a sequence of Point (subclass Curve) Yaml trajectory=\"\"\"\\ name: trajectory shapes: P1: Point(1,-1) P2: P1 + Point(0,2) P3: P2 + Point(-2,0) P4: P3 + Point(0,-2) psq: | [P1,P2,P3,P4] trajectory: Trajectory(psq) \"\"\" Python P1 = Point(1,-1) P2 = P1 + Point(0,2) P3 = P2 + Point(-2,0) P4 = P3 + Point(0,-2) psq = [P1,P2,P3,P4] trajectory = Trajectory(psq) trajectory.draw() curve.set_name(\"trajectory\") Gravity home defines a downward-pointing gravity arrow with the symbol g or user given symbol. Yaml gravity=\"\"\" name: gravity shapes: c: point(0,0) r: 2 gravity: formula: Gravity(c, r, text='$Mg$') \"\"\" Python c = point(0,0) r = 2 gravity = Gravity(c, r, text='$Mg$') gravity.set_name(\"gravity\") Moment home defines a Moment arrow with text given text, center and radius. Yaml moment=\"\"\" name: moment shapes: moment: Moment(\"$T$\", point(0,0), 2) \"\"\" Python moment = Moment(\"$T$\", point(0,0), 2) moment.shape_name=\"moment\" Text_wArrow home Text, but an arrow is drawn from the mid part of the text to some point arrow_tip Yaml txtarrow=\"\"\" name: txtarrow shapes: txtarrow: Text_wArrow(\"$Text$\", point(0,0), point(2,2)) \"\"\" Python txtarrow = Text_wArrow(\"$Text$\", point(0,0), point(2,2)) txtarrow.set_name(\"txtarrow\") Wheel home Hub and spokes Wheel given center, radius, spokes (default 10), inner_radius(default 1/5 of radius) Yaml wheel=\"\"\" name: wheel shapes: wheel: Wheel(point(0,0), 5) \"\"\" Python wheel = Wheel(point(0,0), 5) wheel.set_name(\"wheel\") Spring home Specify a vertical spring, starting at start and with length as total vertical length Yaml spring=\"\"\" name: spring shapes: spring: formula: Spring(point(0,0),5) style: linecolor: black linewidth: 1 \"\"\" Python spring = Spring(point(0,0),5) spring.set_linecolor('black') spring.set_linewidth(1) spring.set_name(\"spring\") Dashpot home Defines a vertical dashpot of height total_length and start as bottom/starting point. Yaml dashpot=\"\"\" name: dashpot shapes: dashpot: Dashpot(point(0,0),5) \"\"\" Python dashpot = Dashpot(point(0,0),5) dashpot.set_name(\"dashpot\") Code to display the above defined shapes home In order to display the various shapes, use the following code in a jupyter notebook [1]: %matplotlib widget [2]: from pysketcher import * [3]: from math import tan, radians, sin, cos # needed for python code [4]: import numpy as np [6]: drawing_tool.set_coordinate_system(xmin=-10, xmax=10,ymin=-10, ymax=10,axis=True) [5]: drawing_tool.mpl.gcf().canvas for Yaml, you need to add those extra steps head = \"\"\"\\ libraries: [\"from math import tan, radians, sin, cos\",\"from pysketcher import *\",\"import numpy as np\"] myfig={} sketch = Sketch(myfig) sketch.append(head) The above code initialize myfig sketch space loading into it libraries references so samples can use tan, radians, si, cos and all the objects defined in pysketcher (the module name of jupytersketcher) and numpy as well: this is used by the yaml definition of shapes Yaml myfig={} sketch=\"\"\" # put here the yaml 'object' definition \"\"\" drawing_tool.erase() sketch.append(sketch) # replace 'object' by the actual one d = myfig['object'].draw() drawing_tool.display() display(SVG(Sketch.matplotlib2SVG())) Python drawing_tool.erase() # put the code of the object case here # replace object by the actual name line, rectangle, circle... object.draw() drawing_tool.display() display(SVG(Sketch.matplotlib2SVG()))","title":"Shapes Reference"},{"location":"shapereference/#list-of-shapes","text":"Code to display shapes Line : defines a line providing start and end point Rectangle : defines a rectangle providing bottom left corner, x dimension, y dimension Triangle : defines a triangle providing three corner Circle : defines a circle proving center and radius Distance with text : defines a sizing mark with a label Text : defines a given text positionned at the provided point Cross : defines a cross positionned at the provided point Axis : defines an axis at the given point with a given label Arc : defines an Arc providing a center point, a radius, a starting angle and an angle (rotates clock-wise) Arc_wText : defines an arc with text positionned left (moving clock-wise) of arc half-way Arrow1 : defines a line with arrow(s) given starting and ending point and arrow termination(s) ->, \\<->, \\<- Force : defines an Indication of a force by an arrow and a text (symbol) Wall : defines an hached box given starting, ending point and thickness, filled with a pattern Curve : defines a general curve as a sequence of (x,y) coordinates Trajectory : defines a general curve as a sequence of Point (subclass Curve) Gravity : defines a downward-pointing gravity arrow with the symbol g or user given symbol. Moment : defines a Moment arrow with text given text, center and radius Text_wArrow : defines Text, but an arrow is drawn from the mid part of the text to some point arrow_tip Wheel : defines Hub and spokes Wheel given center, radius, spokes (default 10), inner_radius(default 1/5 of radius) Spring : defines a vertical spring, starting at start and with length as total vertical length Dashpot : defines a vertical dashpot of height total_length and start as bottom/starting point.","title":"List of Shapes"},{"location":"shapereference/#line","text":"home Defines a line providing start and end point","title":"Line"},{"location":"shapereference/#yaml","text":"name: line shapes: A: point(-5,-5) B: point(5,5) line: Line(A,B)","title":"Yaml"},{"location":"shapereference/#python","text":"A = point(-5,-5) B = point(5,5) line = Line(A,B) line.set_name(\"line\")","title":"Python"},{"location":"shapereference/#rectangle","text":"home Defines a rectangle providing bottom left corner, x dimension, y dimension","title":"Rectangle"},{"location":"shapereference/#yaml_1","text":"name: rectangle shapes: L: 8 h: 5 p: point(-(L/2),-(h/2)) rectangle: Rectangle(p,L,h)","title":"Yaml"},{"location":"shapereference/#python_1","text":"L = 8 h = 5 p = point(-(L/2),-(h/2)) rectangle = Rectangle(p,L,h) rectangle.set_name(\"rectangle\")","title":"Python"},{"location":"shapereference/#circle","text":"home Defines a circle proving center and radius","title":"Circle"},{"location":"shapereference/#yaml_2","text":"name: circle shapes: circle: Circle(point(0,0),5)","title":"Yaml"},{"location":"shapereference/#python_2","text":"circle = Circle(point(0,0),5) circle.set_name(\"circle\")","title":"Python"},{"location":"shapereference/#triangle","text":"home Defines a triangle providing three corner","title":"Triangle"},{"location":"shapereference/#yaml_3","text":"name: triangle shapes: L: 3.0 W: 4.0 triangle: Triangle(p1=(W/2,0), p2=(3*W/2,W/2), p3=(4*W/5.,L))","title":"Yaml"},{"location":"shapereference/#python_3","text":"L = 3.0 W = 4.0 triangle = Triangle(p1=(W/2,0), p2=(3*W/2,W/2), p3=(4*W/5.,L)) triangle.set_name(\"triangle\")","title":"Python"},{"location":"shapereference/#distance-with-text","text":"home Defines a sizing mark with a label","title":"Distance with text"},{"location":"shapereference/#yaml_4","text":"name: dwt shapes: fontsize: 14 t: r'$ 2\\pi R^2 $' # sample text dwt: Distance_wText((-4,0), (8, 5), t, fontsize)","title":"Yaml"},{"location":"shapereference/#python_4","text":"fontsize=14 t = r'$ 2\\pi R^2 $' # sample text dwt = Distance_wText((-4,0), (8, 5), t, fontsize) dwt.set_name(\"dwt\")","title":"Python"},{"location":"shapereference/#text","text":"home Defines a given text positionned at the provided point","title":"Text"},{"location":"shapereference/#yaml_5","text":"name: text shapes: text: Text(r'$c$', point(0,0))","title":"Yaml"},{"location":"shapereference/#python_5","text":"text = Text(r'$c$', point(0,0)) text.set_name(\"text\")","title":"Python"},{"location":"shapereference/#cross","text":"home Defines a cross positionned at the provided point","title":"Cross"},{"location":"shapereference/#yaml_6","text":"name: cross shapes: cross: Cross(point(0,0))","title":"Yaml"},{"location":"shapereference/#python_6","text":"cross = Cross(point(1,0)) cross.set_name(\"cross\")","title":"Python"},{"location":"shapereference/#axis","text":"home Defines an axis at the given point with a given label","title":"Axis"},{"location":"shapereference/#yaml_7","text":"name: axis shapes: axis: Axis((0,0), 5, 'x', rotation_angle=0)","title":"Yaml"},{"location":"shapereference/#python_7","text":"axis = Axis((0,0), 5, 'x', rotation_angle=0) axis.set_name(\"axis\")","title":"Python"},{"location":"shapereference/#arc","text":"home Defines an Arc providing a center point, a radius, a starting angle and an angle (rotates clock-wise)","title":"Arc"},{"location":"shapereference/#yaml_8","text":"name: arc shapes: center: point(0,0) radius: 1 angle: 120 start_angle: 180-angle arc_angle: angle arc: Arc(center, radius, start_angle, arc_angle)","title":"Yaml"},{"location":"shapereference/#python_8","text":"center = point(0,0) radius = 1 angle = 120 start_angle = 180-angle arc_angle = angle arc = Arc(center, radius, start_angle, arc_angle) arc.set_name(\"arc\")","title":"Python"},{"location":"shapereference/#arc_wtext","text":"home Defines an arc with text positionned left (moving clock-wise) of arc half-way","title":"Arc_wText"},{"location":"shapereference/#yaml_9","text":"name: arc_wtxt shapes: center: point(0,0) radius: 1 angle: 120 start_angle: 180-angle arc_angle: angle arc_wtxt: \"Arc_wText(r'$<bslash>theta$', center, radius, start_angle, arc_angle)\"","title":"Yaml"},{"location":"shapereference/#python_9","text":"center = point(0,0) radius = 1 angle = 120 start_angle = 180-angle arc_angle = angle arc_wtxt = Arc_wText(r'$\\theta$', center, radius, start_angle, arc_angle) arc_wtxt.set_name(\"arcwtxt\")","title":"Python"},{"location":"shapereference/#arrow1","text":"home defines a line with arrow(s) given starting and ending point and arrow termination(s) ->, \\<->, \\<-","title":"Arrow1"},{"location":"shapereference/#yaml_10","text":"name: arrow1 shapes: start: point(0,0) end: point(5,5) arrow1: Arrow1(start, end, style='<->')","title":"Yaml"},{"location":"shapereference/#python_10","text":"start = point(0,0) end = point(5,5) arrow1 = Arrow1(start, end, style='<->') arrow1.set_name(\"arrow1\")","title":"Python"},{"location":"shapereference/#force","text":"home defines an Indication of a force by an arrow and a text (symbol)","title":"Force"},{"location":"shapereference/#yaml_11","text":"name: force shapes: x: 0 y: 0 contact: point(x, y) vector: point(-3,-5) force: Force(contact - vector, contact, r'$Force$', text_pos='start')","title":"Yaml"},{"location":"shapereference/#python_11","text":"x = 0 y = 0 contact = point(x, y) vector = point(-3,-5) force = Force(contact - vector, contact, r'$Force$', text_pos='start') force.set_name(\"force\")","title":"Python"},{"location":"shapereference/#wall","text":"home defines an hached box given starting, ending point and thickness, filled with a pattern","title":"Wall"},{"location":"shapereference/#yaml_12","text":"name: wall shapes: theta: 30 L: 8 B: point(L-4,-2) # wall right end A: point(-4,tan(radians(theta))*L-2) # wall left end wall: formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.5,transparent=False) style: linecolor: black","title":"Yaml"},{"location":"shapereference/#python_12","text":"theta = 30 L = 8 B = point(L-4,-2) # wall right end A = point(-4,tan(radians(theta))*L-2) # wall left end wall= Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.5,transparent=False) wall.set_linecolor('black') wall.set_name(\"wall\")","title":"Python"},{"location":"shapereference/#curve","text":"home defines a general curve as a sequence of (x,y) coordinates","title":"Curve"},{"location":"shapereference/#yaml_13","text":"curve=\"\"\"\\ name: curve shapes: N: 100 x: np.linspace(-2.0, 2.0, N) y: x**3 curve: Curve(x,y) \"\"\"","title":"Yaml"},{"location":"shapereference/#python_13","text":"N = 100 x = np.linspace(-2.0, 2.0, N) y = x**3 curve = Curve(x,y) curve.draw() curve.set_name(\"curve\")","title":"Python"},{"location":"shapereference/#trajectory","text":"home defines a general curve as a sequence of Point (subclass Curve)","title":"Trajectory"},{"location":"shapereference/#yaml_14","text":"trajectory=\"\"\"\\ name: trajectory shapes: P1: Point(1,-1) P2: P1 + Point(0,2) P3: P2 + Point(-2,0) P4: P3 + Point(0,-2) psq: | [P1,P2,P3,P4] trajectory: Trajectory(psq) \"\"\"","title":"Yaml"},{"location":"shapereference/#python_14","text":"P1 = Point(1,-1) P2 = P1 + Point(0,2) P3 = P2 + Point(-2,0) P4 = P3 + Point(0,-2) psq = [P1,P2,P3,P4] trajectory = Trajectory(psq) trajectory.draw() curve.set_name(\"trajectory\")","title":"Python"},{"location":"shapereference/#gravity","text":"home defines a downward-pointing gravity arrow with the symbol g or user given symbol.","title":"Gravity"},{"location":"shapereference/#yaml_15","text":"gravity=\"\"\" name: gravity shapes: c: point(0,0) r: 2 gravity: formula: Gravity(c, r, text='$Mg$') \"\"\"","title":"Yaml"},{"location":"shapereference/#python_15","text":"c = point(0,0) r = 2 gravity = Gravity(c, r, text='$Mg$') gravity.set_name(\"gravity\")","title":"Python"},{"location":"shapereference/#moment","text":"home defines a Moment arrow with text given text, center and radius.","title":"Moment"},{"location":"shapereference/#yaml_16","text":"moment=\"\"\" name: moment shapes: moment: Moment(\"$T$\", point(0,0), 2) \"\"\"","title":"Yaml"},{"location":"shapereference/#python_16","text":"moment = Moment(\"$T$\", point(0,0), 2) moment.shape_name=\"moment\"","title":"Python"},{"location":"shapereference/#text_warrow","text":"home Text, but an arrow is drawn from the mid part of the text to some point arrow_tip","title":"Text_wArrow"},{"location":"shapereference/#yaml_17","text":"txtarrow=\"\"\" name: txtarrow shapes: txtarrow: Text_wArrow(\"$Text$\", point(0,0), point(2,2)) \"\"\"","title":"Yaml"},{"location":"shapereference/#python_17","text":"txtarrow = Text_wArrow(\"$Text$\", point(0,0), point(2,2)) txtarrow.set_name(\"txtarrow\")","title":"Python"},{"location":"shapereference/#wheel","text":"home Hub and spokes Wheel given center, radius, spokes (default 10), inner_radius(default 1/5 of radius)","title":"Wheel"},{"location":"shapereference/#yaml_18","text":"wheel=\"\"\" name: wheel shapes: wheel: Wheel(point(0,0), 5) \"\"\"","title":"Yaml"},{"location":"shapereference/#python_18","text":"wheel = Wheel(point(0,0), 5) wheel.set_name(\"wheel\")","title":"Python"},{"location":"shapereference/#spring","text":"home Specify a vertical spring, starting at start and with length as total vertical length","title":"Spring"},{"location":"shapereference/#yaml_19","text":"spring=\"\"\" name: spring shapes: spring: formula: Spring(point(0,0),5) style: linecolor: black linewidth: 1 \"\"\"","title":"Yaml"},{"location":"shapereference/#python_19","text":"spring = Spring(point(0,0),5) spring.set_linecolor('black') spring.set_linewidth(1) spring.set_name(\"spring\")","title":"Python"},{"location":"shapereference/#dashpot","text":"home Defines a vertical dashpot of height total_length and start as bottom/starting point.","title":"Dashpot"},{"location":"shapereference/#yaml_20","text":"dashpot=\"\"\" name: dashpot shapes: dashpot: Dashpot(point(0,0),5) \"\"\"","title":"Yaml"},{"location":"shapereference/#python_20","text":"dashpot = Dashpot(point(0,0),5) dashpot.set_name(\"dashpot\")","title":"Python"},{"location":"shapereference/#code-to-display-the-above-defined-shapes","text":"home In order to display the various shapes, use the following code in a jupyter notebook [1]: %matplotlib widget [2]: from pysketcher import * [3]: from math import tan, radians, sin, cos # needed for python code [4]: import numpy as np [6]: drawing_tool.set_coordinate_system(xmin=-10, xmax=10,ymin=-10, ymax=10,axis=True) [5]: drawing_tool.mpl.gcf().canvas for Yaml, you need to add those extra steps head = \"\"\"\\ libraries: [\"from math import tan, radians, sin, cos\",\"from pysketcher import *\",\"import numpy as np\"] myfig={} sketch = Sketch(myfig) sketch.append(head) The above code initialize myfig sketch space loading into it libraries references so samples can use tan, radians, si, cos and all the objects defined in pysketcher (the module name of jupytersketcher) and numpy as well: this is used by the yaml definition of shapes","title":"Code to display the above defined shapes"},{"location":"shapereference/#yaml_21","text":"myfig={} sketch=\"\"\" # put here the yaml 'object' definition \"\"\" drawing_tool.erase() sketch.append(sketch) # replace 'object' by the actual one d = myfig['object'].draw() drawing_tool.display() display(SVG(Sketch.matplotlib2SVG()))","title":"Yaml"},{"location":"shapereference/#python_21","text":"drawing_tool.erase() # put the code of the object case here # replace object by the actual name line, rectangle, circle... object.draw() drawing_tool.display() display(SVG(Sketch.matplotlib2SVG()))","title":"Python"},{"location":"yamlsketcher/","text":"Content YAML sketcher file grammar Libraries, Pysketcher Object creation, Styles, Transform Example Code to read or write a yaml sketcher file YAML sketcher file grammar Sketcher file EBNF Grammar is Sketch::= Sketch_Name Parts Sketch_Name::= \"-\" \" \" \"name: \" Identifier Comment? \"\\n\" Parts::= \"-\" \" \" \"parts:\\n\" Comment? Part+ Part::= Part_Name Shapes Part_Name::= INDENT \"-\" \" \" \"name: \" Identifier Comment? \"\\n\" DEDENT Shapes::= INDENT \" \" \" \" \"shapes:\\n\" Comment? Shape+ DEDENT Shape::= Simple | DoAction | SketchObject Simple::= INDENT Identifier \":\" PyRightHandExpression Comment? \"\\n\" DEDENT DoAction::= INDENT Identifier \":\" Comment? \"\\n\" Action DEDENT Action::= INDENT \"action:\" PyExpression Comment? \"\\n\" DEDENT Identifier::= [A-Za-z][_A-Za-z0-9]+ Comment::= \"#\" STRING Here is the railroad grammar diagram: Yaml Sketcher railroad diagram [Built thanks] Libraries, Pysketcher Object creation, Styles, Transform Libraries The libraries token defined in the grammar is a single import directive a list [] of import directive one of the import must be pysketcher! from pysketcher import * Pysketcher object creation The Python pysktecher object creation is a python class object statment. The possible class are defined in this section Every parameter of the object creation can be an expression, based upon variables defined before in the YAML file Styles The list of possible style correspond to the list of set_<style> members of the corresponding pysketcher class used for the object creation. This function will be applied to the current object under creation. Parameters of this function can be variable defined upstream. Transform The transform token defined in the grammer is a single transform statement a list [] of transform statments a tranform statement is a transformation function that can be applied to the object under construction example of transform function are rotate, translate parameters of the transform function can be expression based upon upstream variables definition Example !!omap - name: unknown - parts: - name: head shapes: libraries: ['from math import tan, radians, sin, cos', from pysketcher import *] - name: constants shapes: fontsize: 18 # size of the characters g: 9.81 # constant gravity theta: 30.0 # inclined plane angle L: 10.0 # sketch sizing parameter a: 1.0 # xmin: 0.0 # sketech min Abscissa ymin: -3.0 # sketech min Ordinate rl: 2.0 # rectangle width rL: 1.0 # rectangle length - name: frame shapes: setframe: # sketch setup action: drawing_tool.set_coordinate_system(xmin=xmin-L/5, xmax=xmin+1.5*L,ymin=ymin, ymax=ymin+1.5*L,instruction_file='tmp_mpl_friction.py') setblackline: # default frame values and actions action: drawing_tool.set_linecolor('black') B: point(a+L,0) # wall right end A: point(a,tan(radians(theta))*L) # wall left end normal_vec: point(sin(radians(theta)),cos(radians(theta))) # Vector normal to wall tangent_vec: point(cos(radians(theta)),-sin(radians(theta))) # Vector tangent to wall help_line: Line(A,B) # wall line x: a + 3*L/10. # contact point Abscissa y: help_line(x=x) # contact point Ordinate contact: point(x, y) # contact point: middle of the rectangle bottom edge c: contact + rL/2*normal_vec - name: body shapes: rectangle: formula: Rectangle(contact, rl, rL) style: linecolor: blue filled_curves: blue transform: ['rotate(-theta, contact)', translate(-rl/2*tangent_vec)] N: formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start') style: linecolor: black wheel: formula: \"Composition({'outer': rectangle})\" style: shadow: 1 mc: formula: Text(r'$c$', c) body: formula: \"Composition({'wheel': wheel, 'N': N, 'mc': mc})\" style: linecolor: black - name: plan shapes: mB: formula: Text(r'$B$',B) mA: formula: Text(r'$A$', A) wall: formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False) style: linecolor: black x_const: formula: Line(contact, contact + point(0,4)) style: linestyle: dotted transform: rotate(-theta, contact) x_axis: formula: Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta) plan: formula: \"Composition({'body': body, 'inclined wall': wall, 'x start': x_const,\\ \\ 'x axis': x_axis, 'mA': mA, 'mB': mB})\" - name: friction shapes: mg: formula: Gravity(c, rl, text='$Mg$') style: linecolor: black angle: formula: Arc_wText(r'$<bslash>theta$', center=B, radius=3, start_angle=180-theta, arc_angle=theta, fontsize=fontsize) style: linecolor: black linewidth: 1 ground: formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0)) stlye: linecolor: black linestyle: dashed linewidth: 1 friction: formula: \"Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle':\\ \\ angle})\" Code to read or write a yaml sketcher file To read a YAML Pysketcher file definition: from pysketcher import * myfig={} sketch = Sketch(myfig) sketch.file2Sketch(\"dryfriction.yml\") #............... can now use sketch to draw something .................. To write a YAML Pysketcher file definition: from pysketcher import * myfig={} sketch = Sketch(myfig) #............. need to create some Pysketcher objects in the sketch ................. sketch.file2Sketch(\"dryfriction.yml\")","title":"YAML files Reference"},{"location":"yamlsketcher/#yaml-sketcher-file-grammar","text":"Sketcher file EBNF Grammar is Sketch::= Sketch_Name Parts Sketch_Name::= \"-\" \" \" \"name: \" Identifier Comment? \"\\n\" Parts::= \"-\" \" \" \"parts:\\n\" Comment? Part+ Part::= Part_Name Shapes Part_Name::= INDENT \"-\" \" \" \"name: \" Identifier Comment? \"\\n\" DEDENT Shapes::= INDENT \" \" \" \" \"shapes:\\n\" Comment? Shape+ DEDENT Shape::= Simple | DoAction | SketchObject Simple::= INDENT Identifier \":\" PyRightHandExpression Comment? \"\\n\" DEDENT DoAction::= INDENT Identifier \":\" Comment? \"\\n\" Action DEDENT Action::= INDENT \"action:\" PyExpression Comment? \"\\n\" DEDENT Identifier::= [A-Za-z][_A-Za-z0-9]+ Comment::= \"#\" STRING Here is the railroad grammar diagram: Yaml Sketcher railroad diagram [Built thanks]","title":"YAML sketcher file grammar"},{"location":"yamlsketcher/#libraries-pysketcher-object-creation-styles-transform","text":"","title":"Libraries, Pysketcher Object creation, Styles, Transform"},{"location":"yamlsketcher/#libraries","text":"The libraries token defined in the grammar is a single import directive a list [] of import directive one of the import must be pysketcher! from pysketcher import *","title":"Libraries"},{"location":"yamlsketcher/#pysketcher-object-creation","text":"The Python pysktecher object creation is a python class object statment. The possible class are defined in this section Every parameter of the object creation can be an expression, based upon variables defined before in the YAML file","title":"Pysketcher object creation"},{"location":"yamlsketcher/#styles","text":"The list of possible style correspond to the list of set_<style> members of the corresponding pysketcher class used for the object creation. This function will be applied to the current object under creation. Parameters of this function can be variable defined upstream.","title":"Styles"},{"location":"yamlsketcher/#transform","text":"The transform token defined in the grammer is a single transform statement a list [] of transform statments a tranform statement is a transformation function that can be applied to the object under construction example of transform function are rotate, translate parameters of the transform function can be expression based upon upstream variables definition","title":"Transform"},{"location":"yamlsketcher/#example","text":"!!omap - name: unknown - parts: - name: head shapes: libraries: ['from math import tan, radians, sin, cos', from pysketcher import *] - name: constants shapes: fontsize: 18 # size of the characters g: 9.81 # constant gravity theta: 30.0 # inclined plane angle L: 10.0 # sketch sizing parameter a: 1.0 # xmin: 0.0 # sketech min Abscissa ymin: -3.0 # sketech min Ordinate rl: 2.0 # rectangle width rL: 1.0 # rectangle length - name: frame shapes: setframe: # sketch setup action: drawing_tool.set_coordinate_system(xmin=xmin-L/5, xmax=xmin+1.5*L,ymin=ymin, ymax=ymin+1.5*L,instruction_file='tmp_mpl_friction.py') setblackline: # default frame values and actions action: drawing_tool.set_linecolor('black') B: point(a+L,0) # wall right end A: point(a,tan(radians(theta))*L) # wall left end normal_vec: point(sin(radians(theta)),cos(radians(theta))) # Vector normal to wall tangent_vec: point(cos(radians(theta)),-sin(radians(theta))) # Vector tangent to wall help_line: Line(A,B) # wall line x: a + 3*L/10. # contact point Abscissa y: help_line(x=x) # contact point Ordinate contact: point(x, y) # contact point: middle of the rectangle bottom edge c: contact + rL/2*normal_vec - name: body shapes: rectangle: formula: Rectangle(contact, rl, rL) style: linecolor: blue filled_curves: blue transform: ['rotate(-theta, contact)', translate(-rl/2*tangent_vec)] N: formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start') style: linecolor: black wheel: formula: \"Composition({'outer': rectangle})\" style: shadow: 1 mc: formula: Text(r'$c$', c) body: formula: \"Composition({'wheel': wheel, 'N': N, 'mc': mc})\" style: linecolor: black - name: plan shapes: mB: formula: Text(r'$B$',B) mA: formula: Text(r'$A$', A) wall: formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False) style: linecolor: black x_const: formula: Line(contact, contact + point(0,4)) style: linestyle: dotted transform: rotate(-theta, contact) x_axis: formula: Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta) plan: formula: \"Composition({'body': body, 'inclined wall': wall, 'x start': x_const,\\ \\ 'x axis': x_axis, 'mA': mA, 'mB': mB})\" - name: friction shapes: mg: formula: Gravity(c, rl, text='$Mg$') style: linecolor: black angle: formula: Arc_wText(r'$<bslash>theta$', center=B, radius=3, start_angle=180-theta, arc_angle=theta, fontsize=fontsize) style: linecolor: black linewidth: 1 ground: formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0)) stlye: linecolor: black linestyle: dashed linewidth: 1 friction: formula: \"Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle':\\ \\ angle})\"","title":"Example"},{"location":"yamlsketcher/#code-to-read-or-write-a-yaml-sketcher-file","text":"To read a YAML Pysketcher file definition: from pysketcher import * myfig={} sketch = Sketch(myfig) sketch.file2Sketch(\"dryfriction.yml\") #............... can now use sketch to draw something .................. To write a YAML Pysketcher file definition: from pysketcher import * myfig={} sketch = Sketch(myfig) #............. need to create some Pysketcher objects in the sketch ................. sketch.file2Sketch(\"dryfriction.yml\")","title":"Code to read or write a yaml sketcher file"}]}