Gabriel
Gabriel

Reputation: 42439

Angle between intersecting planes drawn with matplotlib

I need to produce a plot with intersecting planes, similar to the one presented in the question: How to draw intersecting planes?. The accepted answer in that question is a great piece of code by tcaswell (code is below).

In that code, a var angle is used which apparently controls the angle between each planes. For small values it certainly behaves like that, but for larger values it does not.

For example, these are the results for the values angle = 0.25, 0.5, 1, 5, 50, 100.

enter image description here

The variable obviously has an effect over the angle between the planes, but it also controls the extension of the inclined plane. At first I though angles was expressed in radians, but it is not. It's also not expressed in degrees, as seen in the image above where it never seems to reach a 90º angle between the planes.

The questions are then: what is that variable doing?, and: how can I control the angle between the planes?


Code:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np


fig = plt.figure()
ax = Axes3D(fig)

dim = 10

# Define x,y plane.
X, Y = np.meshgrid([-dim, dim], [-dim, dim])
Z = np.zeros((2, 2))

# Define inclined plane.
angle = 0.5  # <-- This is the variable
X2, Y2 = np.meshgrid([-dim, dim], [0, dim])
Z2 = Y2 * angle
X3, Y3 = np.meshgrid([-dim, dim], [-dim, 0])
Z3 = Y3 * angle

# Plot x,y plane.
ax.plot_surface(X, Y, Z, color='gray', alpha=.5, linewidth=0, zorder=1)
# Plot top half of inclined plane.
ax.plot_surface(X2, Y2, Z2, color='blue', alpha=.5, linewidth=0, zorder=3)
# Plot bottom half of inclined plane.
ax.plot_surface(X2, Y3, Z3, color='blue', alpha=.5, linewidth=0, zorder=-1)

ax.set_xlim(-10., 10.)
ax.set_ylim(-10., 10.)
ax.set_zlim(-10., 10.)
plt.show()

Upvotes: 0

Views: 1378

Answers (1)

Schorsch
Schorsch

Reputation: 7915

What is called angle is just a multiplier for the y-coordinate. So for small angles the result is the same, however, for a 90 degree rotation the factor would have to be infinity.

You can redefine the angle using the tanget and providing an input in radians:

angle = np.tan(pi * 0.25)

Now, you will see an actual rotation with a specified angle.

pi*0.25 pi*1/3


a cleaner modification may be:

# Define inclined plane.
angle = pi * 0.5  # <-- This is the variable
X2, Y2 = np.meshgrid([-dim, dim], [0, dim])
Z2 = Y2 * np.tan(angle)
X3, Y3 = np.meshgrid([-dim, dim], [-dim, 0])
Z3 = Y3 * np.tan(angle)

Upvotes: 2

Related Questions