Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

3D rotated circle in matplotlib

My ploted circle with n-generated points looks completely fine in 2D:
Generated circle in 2D (x,y)

However when i tried to plot the circle with half of the points increasing z value and half of them decreasing z value it looks like this:
xyz circle
xz view
I want to make it tilted to the xy plane.
Any idea how to make the circle more circle-like?

Here’s my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import matplotlib.pyplot as plt
import numpy as np
import math 

pi = math.pi

x = []
y= []
z=[]

def PointsInCircum(r,n=1000):
    for j in range(-1,int(n/2)):
        z.append(j)
    for j in range(int(n/2),0,-1):
        z.append(j)
    return [(math.cos(2*pi/n*x)*r,math.sin(2*pi/n*x)*r) for x in range(0,n+1)]
    

xy = (PointsInCircum(100))
ax = plt.axes(projection ='3d')

for j in range(len(xy)):
    curr = xy[j]
    x.append(curr[0])
    y.append(curr[1])

print(len(x))
print(len(y))
print(len(z))

ax.scatter(x, y, z, 'green')

plt.show()

I want my "circle" to be a real circle – with correct increasing and decreasing z values…

>Solution :

The bug is that the z coordinate for the points will not be linearly dependent on the iteration count, but rather it will be linearly dependent on the x (or y) coordinate

If you remove the z calculation from the function PointsInCircum , and then make the following changes

m = 1 #assuming you want it to be inclined at 45deg
z = []
for j in range(len(xy)):
    curr = xy[j]
    x.append(curr[0])
    y.append(curr[1])
    z.append(m*curr[0])

That should work!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading