3D circular motion Matlab - matlab

I'm coding circular motion in Matlab, what is the appropriate formula or technique for circular motion in 3D-space, however I make this phenomena by the circle equation of sin and cos but it just rotates the object in circular motion (object itself) without taking its center, I want rotation with center of circle.
My Code:
for ii = 1:3
circular motion = [5*sin(ii) 5 5*cos(ii)];
%I used gain of 5 in order to give its speed.
%matrix circular motion contains XYZ coordinates.
end
Real life scenario of circular motion about center of circle:
Any suggestions or piece of formula that makes my strings unique are welcomed.

Assuming I understand your requirement correctly, to draw a circle in 3 dimensions, you would need to specify the plane on which the circle rests. Let me assume that the plane is z=1 plane.
So, you could plot a circle using:
t = 0:0.01:2*pi;
plot3(sin(t),cos(t),ones(size(t)));
Which gives this:
Bonus:
For a cool animation, try doing:
t = 0:0.01:2*pi;
comet3(sin(t),cos(t),ones(size(t)));

Related

Mapping ellipse points in space to a 2D plane

Good day to all! My task is as follows: there is an array of points in space that form an ellipse, and this array must be designed on a 2D image (as if we were getting an image from a camera). My problem is that in some cases, instead of an ellipse, I can get a hyperbola, which is not good. How to avoid such cases? I do the mapping in the matlab as follows:
function [u,v] = point2camProjection(point,f,Oc)
K = [f,0,Oc(1);0,f,Oc(2);0,0,1];
UVW = K*point;
u=UVW(1)/UVW(3);
v=UVW(2)/UVW(3);
end
point is the coordinates of the 3D point, f is the focal length of the camera, and Oc is the optical center of the camera.

How to get the coordinate of a pixel that is containing right hand wrist joint, in depth image using kinect?

I captured a depth image of a human body in the room and I collected and saved Skeletal data related to that depth image (the joints of wrists, elbows, ...).
Considering the joints' coordinates are in the camera space and depth image is in depth space, I was able to show the location of the right hand wrist joint on depth image using this code:
depthJointIndices = metadata.DepthJointIndices(:, :, trackedBodies);
plot(depthJointIndices(11,1), depthJointIndices(11,2), '*');
Now I want to know which pixel EXACTLY contains the right hand wrist joint, how can I do this properly?
I thought that I can get the coordinate of x,y of that joint using the code I used to show the right hand wrist joint.
As follows:
depthJointIndices = metadata.DepthJointIndices(:, :, trackedBodies);
x=depthJointIndices(11, 1)
y=depthJointIndices(11, 2)
But x,y are calculated as follows:
x = 303.5220
y = 185.6131
As you can see x,y are Floating-point numbers, but coordinates of pixels can't be Floating-point numbers.
So can anyone help me with this problem? how can I get coordinate of a pixel that is containing right hand wrist joint, in depth image, using kinect?
You can use the following 2 equations to derive the coordinates.
Here,
(U,V) and Z denote screen coordinates and depth value, respectively, Cx and Cy denote the center of a depth map, and fx and fy are the focal lengths of the camera. For Kinect-V1 cameras, fx = fy = 580
You can refer the paper Action Recognition From Depth Maps Using Deep Convolutional Neural Networks by P. Wang et.al for more information.

Intersection between two 3D surfaces

I have two independent 3D shapes; one is a square and another is a cone.
Let's assume the cone lies inside the square. How can I find out that the surface of the cone touches the square's surface when I move the cone in any direction?
It will be helpful if anyone can suggest an algorithm to check whether the surface touches another shape.
I am working with MATLAB, but the underlying logic will be appreciated in any language will be appriciated.
https://in.mathworks.com/matlabcentral/answers/367565-findout-surface-to-surface-intersection-between-two-3d-shapes
There is a relatively easy solution, thanks to the fact that the truncated cone is a convex shape, and finding its AABB is not so hard.
First rotate space so that the cube become axis aligned (and the cone in arbitrary position). Then to find the AABB of the base, is suffices to get the maxima an minima of the coordinates, using the parametric equation, C + R cos t + R' sin t, where C is the position vector of the center, and R, R' two orthogonal radii. You find the limit angles by canceling the derivative.
After finding the extrema on the three coordinates, the global bounding box is the one that surrounds these six points plus the apex.
By comparing the AABB to the cube, you can tell what distance remains before a collision, in any direction.

Calculate image rotation based on old and new positions of two points

I have images of faces in different positions. I want to rotate them, to make the line connecting the eyes always be horizontal. But I don't know how to do this in MATLAB.
And how can I calculate the angle of rotation?
Descriptive drawing of problem:
If you already have the locations of the eyes, then it's easy :) Here's an outline:
%// left eye - right eye
pos = [ 30 90 %// X
80 40]; %// Y
%// The angle equals the arctangent of dy/dx
angle = atan2(diff(pos(2,:)), diff(pos(1,:)));
%// Rotate in the opposite direction
img = imrotate(img, -angle);
Since you seem to have the Image Processing Toolbox, you can also look into the built-in landmark-based registration functions (especially if your transform is not limited to pure rotation), in particular cpselect with a syntax like:
cpselect(moving,fixed)
And then use fitgeotrans to construct the geometrical transform and imwarp to warp the moving image.

How can I project a group of points in 3D space onto a 2D plane in Matlab?

I'm making an animation in Matlab: I have 15 dots moving around in a 3D space. Their XYZ co-ordinates and movement are taken from motion-capture data. I need to show how the dots are moving from the perspective of an observer "in front" of the motion. What I'm trying right now is to create a 2D plane and to move it towards the dots so that they end up "projected" onto it. However, it's not a standard X-Y or Y-Z plane, so I'm having trouble figuring out how to make this work.
How can I make this plane do what I want - or is there another way I should be trying?
What you're aiming for is basically implementing an ideal pinhole camera, where the pinhole becomes a point in space. Each of your 3D points plus the "pinhole" defines a line in 3D space, which intersects with your projection plane at some point. It looks somewhat like this:
x_1 and y_1 should have the same length, i.e. 1, so "x" in 3D space is defined as x = o_1 + a * x_1 + b * y_1. In your 2D projection, a and b become your coordinates for plotting.