Plotting a 3d polynomial in python - python

I have a polynomial function, let’s say a+bx+cx^2. I show the function in a 2d plot, but I want to progress to show it in 3d. But not just showing it, giving it height, so if I have x,y I set a Z1 which represents the first layer, and then Z2 which means the second layer, and so on,
or, giving a specific Z, which will create a higher(in height) polynomial function and then somehow connect the dots. So in the end, I will get a shape that is the 3d of that same polynomial but with height.
I don’t know how to get that done, maybe because I can't see another way to do it.
If I represent a 2d function for example:
a+bx+cx^2 function
Now if I want to view it in 3d when the current polynomial is on Z=0, how can I show it when it has height.
I want to view it like this but from 3d:

Related

Animation of image matrices in python

I have a list of (two dimensional) matrices which I want to combine into an animation. The matrices are integer valued with a specified lower and upper bound (in my case from zero to six). I would now like to build an animation where each of the frames consists of the contents of the matrix.
Now, I have managed to get this working if each frame is merely showing the numeric values via matplotlib's built-in matplotlib.pyplot.matshow. Namely, I defined an update function
def update_frames(frame):
animation_image.set_array(matrices[frame])
return animation_image,
where matrices contains the list of integer valued matrices I want to animate. Then, I could pass this into the animation module via
animation_image = ax.imshow(matrices[0])
ani1 = animation.FuncAnimation(fig, update_frames, frames=len(matrices), blit=True)
to obtain the desired result.
I now, however, want to take this a step further by replacing each square on the grid with a specific image, whereas all the images are resized to be of a fixed square shape. For example, at each frame I want to draw a grid of images where the image for each grid cell depends on the integer in the matrix.
Here is a sample animation that I get when using the code snippet above:
I do not have finalized versions of the pictures I would like to show up in the grid yet, but I was thinking of textures that resemble these:
Optimally, I would then end up with grids looking like this (aside from the different placement of objects on the grid as compared to the animation above).
Any help would be greatly appreciated!

glTranslatef gets messed up after glRotatef

I'm a newbie to PyOpenGL. I made a simple code using it that displays a cube, and you can navigate around it using the keyboard. However, I noticed that after a glRotatef command gets called, it changes your perspective, not the positionment of the objects. However, glTranslatef does not work on perspective, and rather a literal coordinate system. In other words, after calling a glRotatef command by 90*, a glTranslatef command that would have moved you forward now moves you to the left. Is there a function like glTranslatef, only it changes with the rotation so you don't get weird motions, or some sort of workaround you can do, to change the values you pass to glTranslatef based on the rotation?
Operations like glTranslate and glRotate define a (translation respectively rotation) matrix and multiply the current matrix by the new matrix.
The matrix multiplication is not commutative. If you want to rotate the model an translate the model independent of the rotation, then you have to do the rotation before the translation respectively multiply the translation matrix by the rotation matrix:
(OpenGL matrix multiplications have to be read from the right to the left):
modelmatrix = translation * rotation
Respectively glTranslate before glRotate:
glTranslate(x, y, z)
glRotate(angle, ax, ay, az)

How to compare the orientation of a 3D vector against a plane in three dimensions

I am currently trying to plot a plane in three dimensional space but not sure how to do it for the problem I have.
Currently I have code that defines a 3D vector according to co-ordinates I have, this includes the ability to rotate, translate, and work out the angle between vectors.
The next step is to define a plane. I am not sure the best way to do this, however. The plane will be in a 100,100,100 box, be flat, and likely exist at a z height of around 30.
My issue comes because I need this plane to do a couple of things:
1: I need to be able to rotate it around the three axes.
2: I need to be able to measure the smallest angle between the plane and the vector I have defined where the vector intersects the plane.
I was initially playing around trying to fill a numpy array with 1s where the plane would be etc but I don't see this really working how I need it to.
Does anyone know of any other tool that I would be able to use in this situation? Many thanks.
First of all, you'll need the normal vector to the plane. From there and following this link it should be easy for you to figure it out :)
Basically you get arcsin of the scalar product of your vector and the normal vector of the plane divided by the product of the norms of both vectors.
PS: If the plane is paralel to the XY plane, then it's normal vector it's just (0,0,1).

function to calculate and plot surface

I have a panel, 3-dimension data table. It's like a grid, just points(x,y,z).
I want to input two of them, then return the other one number, like inputting x and y, return z. But the x, y may not just exist in the grip points, so it needs to calculate by linear or any method.
In addition, I want to plot as a surface.
I googled and found the numpy.meshgrid(), I am confused how to use it. Or could you recommend any package or function could do this task?
Thank you so much !

Plotting 3rd axis as a histogram using color in python

My question is:
I have x and y coordinates, both in degrees. They describe the position of the objects in a region. Now I want to plot something like a histogram, in python, like shown in the figure (done in MATLAB) below
using color codes. It tells how many objects are present over the area. The bin size is 0.5 * 0.5 deg^2. So how can I ?
Secondly, how shall I proceed if I have to plot a third axis instead of just the histogram that describes a different parameter altogether, like some number. I mean just three axes : x, y, z , z being shown in color-code.
Thirdly,
(other questions may be solved after browsing examples shown in comments, but) how to get the data of the color-histogram? To be clear enough, every bin has a particular value, so that it has been shown in the color-bar. But, how can I get the value of each bin and the corresponding points in the form of array I guess, or whatever suitable form may be available?

Categories

Resources