Tychos Docs
  • Tychos Documentation and Reference
  • General
  • Change Log
  • Python Demonstrations
  • MathJs Demonstrations
  • Our Team
  • Learn
    • Overview
    • Creating and Managing Scenarios
    • The Interface
    • Tychos Python Language Reference
    • Tychos MathJs Language Reference
    • Video Guides
      • Video Tutorial: An Overview
      • Video Tutorial: Settings
      • Video Tutorial: Animating Motion
      • Video Tutorial: Meters and Gauges
      • Video Tutorial: Graphs and Bar Charts
      • Video Tutorial: Arrows and Lines
      • Video Tutorial: Tables
  • For Teachers
    • Getting Started
    • Creating and Managing Classes
    • Giving Feedback: Comments
    • Tutorials (Python)
      • Python Tutorial 1: Introduction to Coding in Tychos
      • Python Tutorial 2: Circles and Rectangles
      • Python Tutorial 3: Arrows and Lines (and Poly Lines)
      • Python Tutorial 4: Simulating Change
      • Python Tutorial 5: Simulating Constant Velocity
      • Python Tutorial 6: Using Graphs
      • Python Tutorial 7: Modeling The Momentum Principle
      • Python Tutorial 8: Modeling A Projectile
      • Python Tutorial 9: Conditional Forces
    • Tutorials (MathJs)
      • MathJs Tutorial 1: Introduction to Coding in Tychos
      • MathJs Tutorial 2: Circles and Rectangles
      • MathJs Tutorial 3: Arrows and Lines
      • MathJs Tutorial 4: Simulating Change
      • MathJs Tutorial 5: Simulating Constant Velocity
      • MathJs Tutorial 6: Using Motion Graphs
      • MathJs Tutorial 7: Modeling The Momentum Principle
      • MathJs Tutorial 8: Modeling A Projectile
      • MathJs Tutorial 9: Conditional Forces
    • Writing Goals (Python)
    • Writing Goals (MathJs)
    • Canvas LTI Installation Guide
    • Lesson Worksheets (Google Docs)
Powered by GitBook
On this page
  • Visualizing Vectors
  • Lines (and poly_lines) to Represent Other Geometry

Was this helpful?

  1. For Teachers
  2. Tutorials (Python)

Python Tutorial 3: Arrows and Lines (and Poly Lines)

In addition to the circle and rectangle objects that can be used to represent real world objects, there are other objects that can be used for different visualizations.

PreviousPython Tutorial 2: Circles and RectanglesNextPython Tutorial 4: Simulating Change

Last updated 1 year ago

Was this helpful?

Visualizing Vectors

The class represents a graphical arrow and is commonly used to illustrate vectors, but can be used for representing anything in your simulations.

# Attach an arrow to a circle
c1 = circle(pos=vec(0,0), radius=5, color="green")
a1 = arrow(pos=c1.pos, size=vec(10,10), color="purple")
Arrow without components

The code above creates an arrow object and places the "tail" of the arrow at the position of the circle. The arrow's "tip" then extends in the x direction 10 units, and extends in the y direction 10 units.

The second attribute, the size, should be seen as the actual size of the vector, not the end point of the vector. So for example, if you want to represent the vector (10, 10) but starting at the point (0, 10), notice that the actual tip of the vector extends to the point in space of (10, 20).

  • show_components — This flag tells Tychos to attach additional x and y component arrows.

  • motion_map — This flag tells Tychos to attach a series of strobe images called a motion map.

You can also visualize the vector components by designating the attribute show_components as True.

a1.show_components = True

This will display the component vectors for the diagonal vector.

Lines (and poly_lines) to Represent Other Geometry

Lines can be used to represent things like ropes, strings, wall boundaries, ramps, or really anything that you can imagine that could be idealized as a straight line.

Lines are quite similar to arrows except that they are defined by two positions rather than a position and a size:

# A line representing a string
string = line(pos=vec(0,0), pos2=vec(0,10), color="black", stroke=2)
  • color — HTML color value for your line, e.g. "red" or "#ff0000".

  • motion_map — This flag tells Tychos to attach a series of strobe images called a motion map.

pos — The initial position of your tail as a vector with x,y,z coordinates.

size — The size of the given as a vector with x,y,z coordinates.

color — The will be drawn in this color. Use HTML colors e.g. "#ff3300", "blue".

stroke — The thickness in pixels.

style — An can have a "dash" style, or a "dot" style, or "none" which is the default.

opacity — The will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.

visible — The can be hidden from view by setting this flag to False.

Arrow with components

This creates a with a thickness of 2 pixels, that extends from the point (0,0) to (0, 10). These are other attributes of the line object:

pos — coordinates for the starting point of the as vector

pos2 — coordinates of the termination point of the as a vector.

stroke — Stroke value that determines the visual thickness of the . This is measured in pixels.

style — Sets the as either solid (default = "none") or "dash" for a dashed line, or "dot" for a dotted line.

opacity — The will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.

visible — The can be hidden from view by setting this flag to False.

There is one other object that can also be helpful in creating even more complex geometry in your simulations. These are called objects. They are a collection of objects defined by connecting points.

objects are a bit more complicated, and a bit beyond this introductory tutorial, but here are some links to get you started if you want to learn how to use them:

Tychos Python Language Reference:

Python Demonstrations:

arrow
arrow
arrow
arrow
arrow
arrow
arrow
line
line
line
line
line
line
line
poly_line()
line
poly_line()
poly_line()
poly_line()
arrow