0

I was plotting a car using matplotlib on JupyterLab, a Python distribution offered by Anaconda. I was using Bézier curves to do so.

When I was about to plot the wheels of the car, I realized that it was going to be extremely slow and stressful to get every single point of those many lines and shapes we have inside the Y wheel pattern and plot it. Take a look at it:

enter image description here
So I wanted to know if there was a way to build one shape (a list of points) and iterate over it 360º to repeat the sequence around a central point and make the wheel. My intention is to think as if the shape was the cookie cutter and then I just have to do more cookies using the cutter.

NickS1
  • 496
  • 1
  • 6
  • 19
  • 2
    Yes, it is possible, please post an [mvce](http://stackoverflow.com/help/mcve) so we don't have to guess what your example is. – Reblochon Masque Nov 21 '20 at 04:39
  • Yes, it is possible. Yes, it is cumbersome. The way to go would be to use a vector drawing software, e.g. [Inkscape](https://inkscape.org/). You can also create an SVG file in Inkscape and then [import it into matplotlib](https://stackoverflow.com/questions/31452451/importing-an-svg-file-into-a-matplotlib-figure) – JohanC Nov 21 '20 at 11:48

1 Answers1

0

After a long time, I realized that the answer for my question was here in this other question. The function rotate provided by Mark Dickinson is all I needed. This function rotates a given point, so all I had to do was to apply this function to all the points inside the PATH list of points. Here is how I did it:

def replica(center_of_rotation, times, points, codes, linewidth = 1, c = "black"):
    l = []
    angle = 0
    counter = 1
    while angle <= 360:
        for i in points: 
            l.append(rotate(center_of_rotation, i, math.radians(angle)))
            counter += 1
            if len(l) == len(points):
                ax.add_patch(patches.PathPatch(Path(l, codes), fc="none", transform=ax.transData, color=c, lw = linewidth))
                angle += 360/times
                l = []
            if angle >= 360:
                return

The result was awesome, I can replicate any PATH pattern 'N' number of times. I used this to build the wheels of my Lamborghini.

  • Pattern replicated 1 time:

enter image description here

  • Replicated 5 times, just how much I need:

enter image description here

NickS1
  • 496
  • 1
  • 6
  • 19