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

## Visualizing Vectors

The [`arrow`](https://docs.tychos.org/docs/learn/language-reference-api#arrow) class represents a graphical arrow and is commonly used to illustrate vectors, but can be used for representing anything in your simulations.

```python
# 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")
```

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).

* `pos` — The initial position of your  [`arrow`](https://docs.tychos.org/docs/learn/language-reference-api#arrow)  tail as a vector with `x,y,z` coordinates.
* `size` — The size of the  [`arrow`](https://docs.tychos.org/docs/learn/language-reference-api#arrow)  given as a vector with `x,y,z` coordinates.&#x20;
* `color` — The  [`arrow`](https://docs.tychos.org/docs/learn/language-reference-api#arrow)  will be drawn in this color. Use HTML colors e.g. "#ff3300", "blue".
* `stroke` — The  [`arrow`](https://docs.tychos.org/docs/learn/language-reference-api#arrow)  thickness in pixels.
* `style` — An  [`arrow`](https://docs.tychos.org/docs/learn/language-reference-api#arrow)  can have a "dash" style, or a "dot" style, or "none" which is the default.&#x20;
* `opacity` — The  [`arrow`](https://docs.tychos.org/docs/learn/language-reference-api#arrow)  will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.
* `show_components` — This flag tells Tychos to attach additional x and y component arrows.
* `visible` — The  [`arrow`](https://docs.tychos.org/docs/learn/language-reference-api#arrow)  can be hidden from view by setting this flag to `False`.&#x20;
* `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.

```python
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:

```python
# A line representing a string
string = line(pos=vec(0,0), pos2=vec(0,10), color="black", stroke=2)
```

This creates a [`line`](https://docs.tychos.org/docs/learn/language-reference-api#line) 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 [`line`](https://docs.tychos.org/docs/learn/language-reference-api#line) as vector
* `pos2` — coordinates of the termination point of the [`line`](https://docs.tychos.org/docs/learn/language-reference-api#line)  as a vector.
* `color` — HTML color value for your `line`, e.g. "red" or "#ff0000".
* `stroke` — Stroke value that determines the visual thickness of the[`line`](https://docs.tychos.org/docs/learn/language-reference-api#line) . This is measured in pixels.
* `style` — Sets the [`line`](https://docs.tychos.org/docs/learn/language-reference-api#line)  as either solid (default = "none") or "dash" for a dashed line, or "dot" for a dotted line.
* `opacity` — The [`line`](https://docs.tychos.org/docs/learn/language-reference-api#line)  will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.
* `visible` — The [`line`](https://docs.tychos.org/docs/learn/language-reference-api#line)  can be hidden from view by setting this flag to `False`.
* `motion_map` — This flag tells Tychos to attach a series of strobe images called a motion map.

There is one other object that can also be helpful in creating even more complex geometry in your simulations. These are called [`poly_line()`](https://docs.tychos.org/docs/learn/language-reference-api#poly_line) objects. They are a collection of [`line`](https://docs.tychos.org/docs/learn/language-reference-api#line)  objects defined by connecting points.

[`poly_line()`](https://docs.tychos.org/docs/learn/language-reference-api#poly_line) 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: [`poly_line()`](https://docs.tychos.org/docs/learn/language-reference-api#poly_line)

Python Demonstrations: [`poly_line()`](https://docs.tychos.org/docs/learn/language-reference-api#poly_line)
