# How to Create Unit Circle and Right Sided Triangle / Pythagorean with Plots pyplot

**URL:** <https://discourse.julialang.org/t/how-to-create-unit-circle-and-right-sided-triangle-pythagorean-with-plots-pyplot/82541>\
**Category:** General Usage\
**Tags:** question, plots\
**Created:** [June 10, 2022, 5:44am UTC](https://discourse.julialang.org/t/how-to-create-unit-circle-and-right-sided-triangle-pythagorean-with-plots-pyplot/82541 "2022-06-10T05:44:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [June 10, 2022, 5:44am UTC](https://discourse.julialang.org/t/how-to-create-unit-circle-and-right-sided-triangle-pythagorean-with-plots-pyplot/82541/1 "2022-06-10T05:44:40Z")

</div>

Hi all,

I want to create a right-sided triangle that also has label for the angle and the side name. The question is how?

I have found this that can plot a triangle :

> **[Euclidean Plane Geometry with Julia - You don't need to prove this](http://www2.math.uu.se/~xinca341/euclidean-plane-geometry-with-julia.html)**
>
> The post is generated from a Jupyter notebook. You can also run it live on Binder. Update 2020-05-13: I have …

But still a bit advanced for me to edit and create the label for the angle and the side like hyp, opp, adj.

Next is how to create a unit circle that can have plot on the certain circumference?

Pictures attached.  
Thank You

 ![Capture d’écran_2022-06-10_12-42-51](https://global.discourse-cdn.com/julialang/original/3X/8/3/835c069a9fd1f2b6cd94f72db4bf36483b061ccb.png)

![](https://global.discourse-cdn.com/julialang/original/3X/2/2/222b9753d941f538b4e4c084b7a5dc23a85605fa.png)

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [June 11, 2022, 10:35am UTC](https://discourse.julialang.org/t/how-to-create-unit-circle-and-right-sided-triangle-pythagorean-with-plots-pyplot/82541/2 "2022-06-11T10:35:28Z")

</div>

I already find a way to create the right side triangle

here is the code for anyone want to create a right side triangle:

```julia
using Plots, LaTeXStrings
pyplot()
import Base: isequal, ==

abstract type GeoObject end
abstract type GeoShape <: GeoObject end

struct Point <: GeoObject
    x::Number
    y::Number
end
(==)(p1::Point, p2::Point) = p1.x==p2.x && p1.y==p2.y

struct Triangle <: GeoShape
    A::Point
    B::Point
    C::Point
end
Triangle(ax, ay, bx, by, cx, cy) = Triangle(Point(ax, ay), Point(bx, by), Point(cx, cy))
(==)(t1::Triangle, t2::Triangle) = vertices(t1) == vertices(t2)

function vertices(tri::Triangle) 
    [tri.A, tri.B, tri.C]
end

struct Edge <: GeoShape
    src::Point
    dst::Point
end

function edges(tri::Triangle)
    elist = Edge[]
    pts = vertices(tri)
    for i in 1:length(pts)-1
        push!(elist, Edge(pts[i], pts[i+1]))
    end
    push!(elist, Edge(pts[length(pts)], pts[1]))
    elist
end

struct Circle
    center::Point
    radius::Number
end
(==)(c1::Circle, c2::Circle) = c1.center == c2.center && c1.radius == c2.radius

ccenter(c::Circle) = c.center

A = Point(2,2); B = Point(6, 2); C = Point(6,5);
tri = Triangle(A, B, C)

function shape(ptlist::Vector{Point})
    xlist = [pt.x for pt in ptlist]
    ylist = [pt.y for pt in ptlist]
    shape = Shape(xlist, ylist)
end;
shape(tri::Triangle) = shape(vertices(tri));

trishape=shape(tri)
    
s1 = L"\theta";
s2 = L"sin \ \theta = \frac{opp}{hyp}";
s3 = L"cos \ \theta = \frac{adj}{hyp}";
s4 = L"tan \ \theta = \frac{opp}{adj}";

plot(trishape, leg=false, fill=(0, :green), aspect_ratio=:equal, fillalpha= 0.2)
scatter!(trishape.x, trishape.y, color=:red)
annotate!([(2.3, 2.1, (s1, 14, :red)), 
            (4, 2.1, ("adj", 10, :red)), 
            (6.2, 3.1, ("opp", 10, :red)),
            (4, 3.7, ("hyp", 10, :red)),
            (2.2, 4.5, (s2, 10, :red)), 
            (2.9, 4.5, (s3, 10, :red)),
            (3.6, 4.5, (s4, 10, :red))])

```

 ![rightsidetriangle](https://global.discourse-cdn.com/julialang/original/3X/9/0/908852839582a65614b21ccebbff6f66c77de5cd.png)

and for the unit circle:

```julia
using Plots
pyplot()

function circleShape(h, k, r)
     θ = LinRange(0, 2*π, 500)
     h .+ r*sin.(θ), k .+ r*cos.(θ)
end

plot(circleShape(0, 0, 1), seriestype = [:shape,], lw = 0.5,
      c =:blue, linecolor = :black,
      legend = false, fillalpha = 0.2, aspect_ratio = 1, showaxis = false)
plot!([0], seriestype="vline", color=:green, label="")
plot!([0], seriestype="hline", color=:green, label="")

annotate!([(1.1,0, ("x", 10, :red)), 
           (0.15,1.03, ("y", 10, :red)), 
           (1.15,-0.1, ("A(1,0)", 10, :red)),
           (0.1,-0.1, ("(0,0)", 10, :red)),
           (0.51,0.95, ("(x,y)", 10, :red))])

scatter!([0.50], [0.866025404], color = "red", label="", markersize = 5)

```

 ![Capture d’écran_2022-06-11_22-42-48](https://global.discourse-cdn.com/julialang/original/3X/d/b/db10e6b95d42a89566198d55392ec4a754b25354.png)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 12, 2022, 2:03pm UTC](https://discourse.julialang.org/t/how-to-create-unit-circle-and-right-sided-triangle-pythagorean-with-plots-pyplot/82541/3 "2022-06-12T14:03:23Z")

</div>

FWIW, here is a simple right-angled triangle in the same spirit as your circleShape:

```julia
using Plots

function RightTriangle(x0, y0, θ, L1, L2)
    s, c = sincosd(θ)
    x1, y1 = L1 .* (c,s) 
    return Shape(x0 .+ [0, x1, x1 - L2*s], y0 .+ [0, y1, y1 + L2*c])
end

RT = RightTriangle(0, 0, 30, 1, 2)
plot(RT, lc=:black, lw=0.5, leg=false, ratio=1, c=:green, fa=0.2)
scatter!(RT, c=:red, ms=2.5)

```

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [June 13, 2022, 9:09am UTC](https://discourse.julialang.org/t/how-to-create-unit-circle-and-right-sided-triangle-pythagorean-with-plots-pyplot/82541/4 "2022-06-13T09:09:15Z")

</div>

It works and simpler.

I am changing the length of the sides and the angle to 45 degree

 ![Capture d’écran_2022-06-13_16-08-14](https://global.discourse-cdn.com/julialang/original/3X/3/d/3dc4cbb1de575aa16f36542f3cf16781b639198c.png)
