This question already has answers here:
I need to fit a best circle to the 3D data in matlab
(2 answers)
Closed 7 years ago.
I have my 3D data X,Y,Z (Matrices with size X = 200*1, Y = 200*1, Z = 200*1)
I want to fit the data to the best fit circle
You have 200 pts in 3d space. And a circle also in 3d space, the circle is defined by its centre (3variables), orientation (normal to the circus, so 2 more variables, since its length does not matter) and radius (one more variable), Given a circle and an abitrary point, the distance from the pt to the circle is given by one side of a triangle formed by taking a line from the point to the centre of the triangle then to the radius. This will be defined in terms of the 7 variables (centre, orientation, radius), now you have two hundred distances, sum them and this is a formula in terms of radius, orientation and position, now put this formula inside any of the matlab optimizers and you will find the optimal centre,orientation, radius. This is for sure a convex problem...
Related
This question already has answers here:
How to plot a circle in Matlab?
(2 answers)
How to plot a filled circle?
(1 answer)
Closed 5 years ago.
I know I can plot a dot and select its size with the word 'markersize' like this
plot(0,0,'.','markersize',50) %Dot centered in (0,0)
The size of the dot produced does not change if we amplify the plot. It always seems to have the same size to our eye. I would like to produce dots (or circles) with a real radius, so that when the image is amplified it appears bigger. What are my options?
Use rectangle command with curvature [1 1] it will draw circles with relative radius.
This question already has answers here:
Making Particles Move Randomly Within A Circle [closed]
(2 answers)
Closed 6 years ago.
so i need to generate 10 particles per step in random positions inside the circle to be moving in random directions, and when it hits the wall of the main circle it bounces back and without change in velocity.
I defined the large circle:
yc=0;
rc=5;
ang_c=0:0.01:2*pi;
xpc=rc*cos(ang_c);
ypc=rc*sin(ang_c);
plot(xc+xpc,yc+ypc,'k');
and for now just plotting one particle:
r=0.05;
x=rand;
y=rand;
ang=0:0.01:2*pi;
xp=r*cos(ang);
yp=r*sin(ang);
plot(x+xp,y+yp,'b');
now how to i get the particle to move around in the circle?
Here's an outline of the algorithm
Define a circle (origin, radius)
Create a nParticles-by-2 array particlePositions. Fill it with random coordinates that lie inside the circle
Plot the particle positions, keep the handle returned by plot
Create a nParticles-by-2 array particleSpeeds. Fill it with random speed vectors (ie. x- and y- components). Make sure the norm of the vectors is much smaller than the radius of the circle, at least initially.
Write a loop that updates particle positions:
particlePositions = particlePositions + particleSpeeds;
For any particlePosition would lie outside the circle, calculate where the particle intersected the circle, and reflect the particleSpeed for that particle. This takes a bit of fiddling with trigonometry.
Update the plot: set(plotHandle,'xData',particlePositions(:,1),'yData',particlePositions(:,2))
This question already has answers here:
Image rotation by Matlab without using imrotate
(4 answers)
Closed 7 years ago.
I have a 3D matrix with the dimensions X:24, Y:24, and Z:61397. Z corresponds to the number of frames. when I plot each frame I get an image that is rotated 45 degree clockwise.
I've been trying to rotate the matrix so that the pictures can be straight.(It needs to be rotated 45 degree anticlockwise).
I've tried multiplication by the following rotation matrix based on previous answers for similar question:
% rotation matrix
theta = pi/4;
Rot = makehgtform('xrotate',theta);
Rot = Rot(1:3,1:3);
I got an error due to the difference in size. Do I need to extend the rotation matrix to 24by24? If yes, how?
If all you are doing is rotating an image by 45 degrees you can simply use imrotate.
imrotate(Stack, 45);
where Stack is your 3D matrix.
In case you are looking for a solution which doesn't rely on the image processing toolbox have a look here.
I have this 3 points (x,y) and I need to obtain a mask with a triangle where vertices is the points. I should respect some parameters, like the pixel pitch and I need a grid from the minimum x cordinate to the maximum x coordinate (the same for the y).
I tried to do this in matlab with the function poly2mask but the problem is the resultant image: when I have negative coordinates, I cannot see the polygon.
So I tried to center the polygon but I loose the original coordinates and I cannot have they back again because I need to do some elaboration on the image.
How I can obtain a mask triangle from 3 points without modifying the points and respecting the parameters?
I want to plot 3D cube of size 2x2x5 (x,y,z) around an interest point to get the nearest points to it and inside the cube. The interest point may be at the center of cube.
How can I get the nearest points to the interest point?
There are several techniques for drawing cubes here. You will need to choose one that lets you specify size and origin. The sizes will be 2,2,5, and the origin will be the coordinates of the interest point.