how to cutting 3d plane in my cube (mpl_toolkits.mplot3d.art3d) - mplot3d

enter image description hereI drew a plane using three points.
But one point is outside the cube, so it's out of range. I want to cut the plane inside the cube.
What code should I add?
plane = Poly3DCollection(verts, alpha=.5, facecolor='#0000ff')
enter image description here

Related

How does OpenGL map an image to a quadrilateral?

Image files are rectangular, yet in a 3D environment, a rectangle will appear as an irregular quadrilateral most of the time. Consider the following image (credit to this blog):
Given that:
you already know the four vertices of the green face
you have access to the image file as a 2D array of color values
you are drawing to a screen that is a 2D array of pixels
What is the algorithm that OpenGL uses for drawing the image onto the green face?
The algorithm is basically (if we ignore stuff like shaders for now):
break down the quadrilateral into two triangles
for each triangle, compute the projection onto the image plane
for each screen pixel covered by the projection of the triangle:
compute the texture coordinates by interpolation from the vertices for the position to which the pixel location corresponds on the triangle.
look up the texture image at the location that corresponds to the texture coordinates. Typically, some form of filtering is applied here.
you have found the color for your pixel

how to plot 3D spheres around points with different radius and different origin in Matlab

I have matrix A with size 5x3 which includes 3D (X,Y,Z) coordinates of some points and these points should be center of the spheres. and a vector B with size 5x1 which includes radius of each sphere. How can I plot the spheres around the points with defined radius in vector B and defined center in Matrix A?
Form Matlab docs
Description
The sphere function generates the x-, y-, and z-coordinates of a unit sphere for use with surf and mesh.
sphere generates a sphere consisting of 20-by-20 faces.
sphere(n) draws a surf plot of an n-by-n sphere in the current figure.
You'll need to scale those points by the radius of your sphere and translate them to the appropriate centre. Then plot them. 10 seconds of searching matlab documentation gave me the code to do that as well as to plot the spheres using the surf command.
surf
Create 3-D shaded surface plot

How to calculate a shape based on movement using opencv or other open source lib?

Here is the original image, the green colour is the background, and blue is the shape.
If my eye go closer to the shape, the blue square will be bigger like this:
If my eye go left, the shape will work like this:
I already know my eyes movement position, but how can I calculate what will the shape change? Any recommends? Thanks.
You need know the camera matrix http://en.wikipedia.org/wiki/Camera_matrix it will define the way which 3D coord will be projected to your sreen coordinates. If you know orientation of your camera, then you know 3d coords of object points relative to camera. Applying camera matrix transform to these 3d coords will give you 2d projections in you screen coordinates.

How to find orientation of rubik cube?

I'm trying to make a rubik cube game in webgl using three.js (you can try it here).
And I have problems to detect on witch axis I have to rotate my cube according the rotation of the cube. For instance, if the cube is in original position/rotation, if I want to rotate the left layer from down to up, I must make a rotation on the Y axis. But I rotate my cube 90 degrees on Y, I will have to rotate It on the Z axis to rotate my left layer from down to up.
I'm trying to find a way to get the correct rotation axis according the orientation of the cube.
For the moment I check witch vector of the axis of the rotation matrix of the cube is most parallel with the vector(0,1,0) if I want to move a front layer from down to up. But it do not works in edge cases like this for instance :
I guess there is some simple way to do that, but I'm not good enough in matrix and mathematical stuff :)
An AxisHelper can show the aixs of the scene which you could determine the orientation with.
var axishelper = new THREE.AxisHelper(40);
axishelper.position.y = 300;
scene.add(axishelper);
You could also log your cube and check the position and rotation properties with Chrome Developer Tools or Firebug.
You can store the orientation of each cube in its own 4x4 matrix (i.e. a "model" matrix) that tells you how to get from the cube's local coordinates to the world's coordinates. Now, since you want to rotate the cube around to an axis (i.e. vector) in world coordinates, you need to translate the axis into cube coordinates. This is exactly what the inverse of the model matrix yields.

How to get rotation angles of Image Plane relative to the World Plane?

So we have such situation:
In this illustration, the first quadrilateral is shown on the Image Plane and the second quadrilateral is shown on the World Plane. [1]
In my particular case the Image Plane has 3 quadrilaterals - projections of real world squares, which, as we know, have same size, lying on the same plane, with same rotation relative to the plane they are lying on, and are not situated on same line on plane.
I wonder if we can get rotation angles of Image Plane to World Plane knowing stuff described?
In my case as input I have such data structures: original image (RGB pixels), objects (squares) with angles points in pixels (x,y) on Image Plane.
Take a look at Sections 2 and 3 of Algorithms for plane-based pose estimation.
The methods described there assume that you know the (x,y) coordinates of the features in question - in this case the red squares.
The problem you are describing is generally known as pose estimation - determining the 3D orientation and position of an object relative to a camera from a 2D view. For you, the object is a plane. Googling 'pose estimation plane' should give you more sources.

Resources