Skip to content

Commit

Permalink
Merge pull request #21 from JoelTrent/dev
Browse files Browse the repository at this point in the history
Manually create and add quick start plots
  • Loading branch information
JoelTrent committed Jun 5, 2023
2 parents 136de8f + 4cbb7c7 commit 0c42a03
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 48 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ jobs:
- uses: julia-actions/julia-docdeploy@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GKSwstype: "100"
- run: |
julia --project=docs -e '
using Documenter: DocMeta, doctest
Expand Down
Binary file added docs/src/images/clustered1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/clustered2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/clustered3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/customsampling.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/equallyspaced1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/equallyspaced2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/equallyspaced3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions docs/src/images/quick_start.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using EllipseSampling
using Plots; gr()
Plots.reset_defaults()
default(palette=:seaborn_colorblind6, msw=0, markeralpha=0.7, aspect_ratio=:equal, label=nothing, dpi=150, size=(450,300))
Plots.scalefontsizes(0.75)

function main()
# Equally Spaced Points
e=construct_ellipse(1.0, 0.5, 0.0, 2.0, 1.0)
points=generate_N_equally_spaced_points(9, e; start_point_shift=0.0)
p = scatter(points[1,:], points[2,:])
savefig(p, joinpath("docs", "src", "images", "equallyspaced1.png"))

points=generate_N_equally_spaced_points(9, 1.0, 0.5, 0.0, 2.0, 1.0; start_point_shift=0.0)
p=scatter(points[1,:], points[2,:])
savefig(p, joinpath("docs", "src", "images", "equallyspaced2.png"))

## Rotated Ellipses
e=construct_ellipse(1.0, 0.5, pi/3.0, 2.0, 1.0)
points=generate_N_equally_spaced_points(9, e; start_point_shift=0.0)
p=scatter(points[1,:], points[2,:])
savefig(p, joinpath("docs", "src", "images", "equallyspaced3.png"))

# Clustered Points
e=construct_ellipse(1.0, 0.1, 0.0, 2.0, 1.0)
points=generate_N_clustered_points(30, e; start_point_shift=0.0, sqrt_distortion=0.0)
p=scatter(points[1,:], points[2,:])
savefig(p, joinpath("docs", "src", "images", "clustered1.png"))

p=plot()
e=construct_ellipse(1.0, 0.1, 0.0, 2.0, 1.0)
for sqrt_distortion in 0.0:0.2:1.0
points=generate_N_clustered_points(10, e; start_point_shift=0.0, sqrt_distortion=sqrt_distortion)
scatter!(p, points[1,:], points[2,:], label=string("sqrt_distortion=",sqrt_distortion))
end
savefig(p, joinpath("docs", "src", "images", "clustered2.png"))

p=plot(palette=:Paired_6)
e=construct_ellipse(1.0, 1.0, 0.0, 2.0, 1.0)
for sqrt_distortion in 0.0:0.5:1.0
points=generate_N_clustered_points(10, e; start_point_shift=0.0, sqrt_distortion=sqrt_distortion)
scatter!(p, points[1,:], points[2,:], label=string("sqrt_distortion=",sqrt_distortion),
markersize=7-sqrt_distortion*4, markeralpha=0.8)
end
savefig(p, joinpath("docs", "src", "images", "clustered3.png"))

# Custom Sampling Method
e=construct_ellipse(1.0, 0.5, 0.0, 2.0, 1.0)
N = 100
samples = rand(N)

# wrap e in Ref so that the function correctly broadcasts across samples
points = generate_perimeter_point.(samples, Ref(e))
points = reduce(hcat, points)

p=scatter(points[1,:], points[2,:])
savefig(p, joinpath("docs", "src", "images", "customsampling.png"))
end

main()
76 changes: 29 additions & 47 deletions docs/src/quick_start.md
Original file line number Diff line number Diff line change
@@ -1,108 +1,91 @@
```@setup quick_start
using EllipseSampling
using Pkg; Pkg.add("Plots")
using Plots; gr()
Plots.reset_defaults()
default(palette=:seaborn_colorblind6, msw=0, markeralpha=0.7, aspect_ratio=:equal, label=nothing)
```
# Quick Start

The following plots require these lines to be run first:

```julia
using EllipseSampling, Plots; gr()
default(palette=:seaborn_colorblind6, msw=0, markeralpha=0.7,
aspect_ratio=:equal, label=nothing, dpi=150, size=(450,300))
Plots.scalefontsizes(0.75)
```

## Equally Spaced Points

To generate 9 equally spaced points on an ellipse, with x radius of 1.0 and y radius of 0.5, no rotation and a centre of ``x,y = [2,1]`` we use:

```example quick_start
using EllipseSampling, Plots
```julia
e=construct_ellipse(1.0, 0.5, 0.0, 2.0, 1.0)
points=generate_N_equally_spaced_points(9, e; start_point_shift=0.0)
scatter(points[1,:], points[2,:])
savefig("equalspacing1.svg"); nothing # hide
```

![](equalspacing1.svg)
![](images/equallyspaced1.png)

Or alternatively:
```example quick_start
using EllipseSampling, Plots
```julia
points=generate_N_equally_spaced_points(9, 1.0, 0.5, 0.0, 2.0, 1.0; start_point_shift=0.0)
scatter(points[1,:], points[2,:])
savefig("equalspacing2.svg"); nothing # hide
```

![](equalspacing2.svg)
![](images/equallyspaced2.png)

### Rotated Ellipses

If instead our ellipse has an anticlockwise rotation of ``\\frac{\\pi}{3}`` radians or 60 degrees then we modify that argument to [`construct_ellipse`](@ref).

```example quick_start
using EllipseSampling, Plots
If instead our ellipse has an anticlockwise rotation of ``\frac{\pi}{3}`` radians or 60 degrees, we can modify that argument to [`construct_ellipse`](@ref).

```julia
e=construct_ellipse(1.0, 0.5, pi/3.0, 2.0, 1.0)
points=generate_N_equally_spaced_points(9, e; start_point_shift=0.0)
scatter(points[1,:], points[2,:])
savefig("equalspacing3.svg"); nothing # hide
```


![](equalspacing3.svg)
![](images/equallyspaced3.png)

## Clustered Points

To more easily see the clustering effect we will increase the number of points generated and decrease the y radius. Note, the closer in magnitude the major and minor axis radii are, the weaker the clustering effect.
To generate 30 clustered points on an ellipse, with x radius of 1.0 and y radius of 0.1, no rotation and a centre of ``x,y = [2,1]`` we use:

```example quick_start
using EllipseSampling, Plots
```julia
e=construct_ellipse(1.0, 0.1, 0.0, 2.0, 1.0)
points=generate_N_clustered_points(30, e; start_point_shift=0.0, sqrt_distortion=0.0)
scatter(points[1,:], points[2,:])
savefig("clustering1.svg"); nothing # hide
```

![](clustering1.svg)
![](images/clustered1.png)

The clustering effect becomes weaker when we increase the parameter `sqrt_distortion` towards 1.0:

```example quick_start
using EllipseSampling, Plots
```julia
plot()
e=construct_ellipse(1.0, 0.1, 0.0, 2.0, 1.0)
for sqrt_distortion in 0.0:0.2:1.0
points=generate_N_clustered_points(10, e; start_point_shift=0.0, sqrt_distortion=sqrt_distortion)
scatter!(points[1,:], points[2,:], label=string("sqrt_distortion=",sqrt_distortion))
end
savefig("clustering2.svg"); nothing # hide
```

![](clustering2.svg)
![](images/clustered2.png)

The clustering effect is completely gone if our ellipse is a circle:

```example quick_start
using EllipseSampling, Plots
plot()
```julia
plot(palette=:Paired_6)
e=construct_ellipse(1.0, 1.0, 0.0, 2.0, 1.0)
for sqrt_distortion in 0.0:0.5:1.0
points=generate_N_clustered_points(10, e; start_point_shift=0.0, sqrt_distortion=sqrt_distortion)
scatter!(points[1,:], points[2,:], label=string("sqrt_distortion=",sqrt_distortion),
markersize=7-sqrt_distortion*3, markeralpha=0.5)
scatter!(p, points[1,:], points[2,:], label=string("sqrt_distortion=",sqrt_distortion),
markersize=7-sqrt_distortion*4, markeralpha=0.6)
end
savefig("clustering3.svg"); nothing # hide
```
![](clustering3.svg)

![](images/clustered3.png)

## Custom Sampling Method

If we want to use a custom sampling method different to equal spacing and clustered methods then we can use [`generate_perimeter_point`](@ref) with any arbitrary distribution defined on \[0,1\]. For example, if we want to take 100 uniform random samples (uniform with respect to arc length) of our ellipse perimeter we would use:
If we want to use a custom sampling method different to equal spacing and clustered methods then we can use [`generate_perimeter_point`](@ref) with any arbitrary distribution defined on \[0,1\]. For example, if we want to take quick_start00 uniform random samples (uniform with respect to arc length) of our ellipse perimeter we would use:

```example quick_start
using EllipseSampling, Plots
```julia
e=construct_ellipse(1.0, 0.5, 0.0, 2.0, 1.0)
N = 100
samples = rand(N)
Expand All @@ -112,7 +95,6 @@ points = generate_perimeter_point.(samples, Ref(e))
points = reduce(hcat, points)

scatter(points[1,:], points[2,:])
savefig("customsampling.svg"); nothing # hide
```

![](customsampling.svg)
![](images/customsampling.png)

0 comments on commit 0c42a03

Please sign in to comment.