# Triangle in graph in Julia

**URL:** <https://discourse.julialang.org/t/triangle-in-graph-in-julia/62917>\
**Category:** New to Julia\
**Created:** [June 14, 2021, 10:05pm UTC](https://discourse.julialang.org/t/triangle-in-graph-in-julia/62917 "2021-06-14T22:05:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Izzani\_Nizam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/izzani_nizam/32/25709_2.png) [@Izzani\_Nizam](https://discourse.julialang.org/u/Izzani_Nizam)\
**Post date:** [June 14, 2021, 10:05pm UTC](https://discourse.julialang.org/t/triangle-in-graph-in-julia/62917/1 "2021-06-14T22:05:43Z")

</div>

how could I draw a parallel line and perpendicular line of a straight line?  
could I make a triangle shape in Julia just like the Pythagoras theorem?

thank you

---

<div class="post-metadata">

**Author:** ![Erasmo98](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erasmo98/32/26098_2.png) [@Erasmo98](https://discourse.julialang.org/u/Erasmo98)\
**Post date:** [June 14, 2021, 10:45pm UTC](https://discourse.julialang.org/t/triangle-in-graph-in-julia/62917/2 "2021-06-14T22:45:37Z")

</div>

This can be done using `Plots`. You can draw a line segment with ends (x\_1, y\_1) and (x\_2, y\_2) as follows.

```julia
using Plots
xs = [x₁, x₂]
ys = [y₁, y₂]
plot(xs, ys)

```

We can do the same thing to draw a triangle. If your triangle has vertices (x\_1, y\_1),\, (x\_2, y\_2), and (x\_3, y\_3) you can draw it doing

```julia
using Plots
xs = [x₁, x₂, x₃, x₁] # Vertices' x-component
ys = [y₁, y₂, y₃, y₁] # Vertices' y-component
plot(xs, ys)

```

The triangle has three sides so at least we need four points to draw the three of them, that’s why `x₁` and `y₁` are repeated at the start and end of `xs` and `ys`.

The triangle can also be drawn using [`Compose`](https://giovineitalia.github.io/Compose.jl/latest/):

```julia
using Compose
vertices = [(x₁, y₁), (x₂, y₂), (x₃, y₃)]
compose(context(), polygon(vertices))

```
