-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add spiral target shape #192
base: main
Are you sure you want to change the base?
Changes from all commits
f71a596
f00940f
ca23273
2e1f7c1
2e86a37
779380b
dbc4e76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||||||
"""Shapes that are composed of points.""" | ||||||||||
|
||||||||||
import itertools | ||||||||||
import math | ||||||||||
from numbers import Number | ||||||||||
|
||||||||||
import numpy as np | ||||||||||
|
@@ -304,3 +305,51 @@ def distance(self, x: Number, y: Number) -> int: | |||||||||
Always returns 0 to allow for scattering of the points. | ||||||||||
""" | ||||||||||
return 0 | ||||||||||
|
||||||||||
|
||||||||||
class Spiral(PointCollection): | ||||||||||
""" | ||||||||||
Class for the spiral shape. | ||||||||||
|
||||||||||
.. plot:: | ||||||||||
:scale: 100 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep all the plots the same size:
Suggested change
|
||||||||||
:caption: | ||||||||||
This shape is generated using the panda dataset. | ||||||||||
|
||||||||||
from data_morph.data.loader import DataLoader | ||||||||||
from data_morph.shapes.points import Spiral | ||||||||||
|
||||||||||
_ = Spiral(DataLoader.load_dataset('panda')).plot() | ||||||||||
|
||||||||||
Parameters | ||||||||||
---------- | ||||||||||
dataset : Dataset | ||||||||||
The starting dataset to morph into other shapes. | ||||||||||
|
||||||||||
Notes | ||||||||||
----- | ||||||||||
The formula for a spiral can be found here: | ||||||||||
https://en.wikipedia.org/wiki/Archimedean_spiral | ||||||||||
Comment on lines
+329
to
+332
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great, thank you! |
||||||||||
""" | ||||||||||
|
||||||||||
def __init__(self, dataset: Dataset) -> None: | ||||||||||
xmin, xmax = dataset.data_bounds.x_bounds | ||||||||||
ymin, ymax = dataset.data_bounds.y_bounds | ||||||||||
|
||||||||||
# Coordinates of centre | ||||||||||
cx = dataset.df.x.mean() | ||||||||||
cy = dataset.df.y.mean() | ||||||||||
|
||||||||||
# Max radius | ||||||||||
radius = min(xmax - xmin, ymax - ymin) / 2 | ||||||||||
|
||||||||||
# Number of rotations | ||||||||||
num_rotations = 3 | ||||||||||
|
||||||||||
t = np.linspace(0, 1, num=200) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a comment for this one too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two other thoughts here:
|
||||||||||
|
||||||||||
# x and y calculations for a spiral | ||||||||||
x = (t * radius) * np.cos(2 * num_rotations * math.pi * t) + cx | ||||||||||
y = (t * radius) * np.sin(2 * num_rotations * math.pi * t) + cy | ||||||||||
Comment on lines
+352
to
+353
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Comment on lines
+352
to
+353
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
super().__init__(*np.stack([x, y], axis=1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's stick with numpy for this.