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))
Related
I am trying to count the number of spheres based on intensity value. The spheres are biomarkers from a CT scan. Therefore the center has the largest intensity. However, it is hard for me to count the spheres if there are overlaps. How can we figure out how to do the count of the spheres with overlap.
for a 3D binary image, you can call bwlabeln (https://www.mathworks.com/help/images/ref/bwlabeln.html) in the image processing toolbox to count/label isolated islands, but this can be slow.
if you download my iso2mesh toolbox (http://github.com/fangq/iso2mesh), you can also try the bwislands function
https://github.com/fangq/iso2mesh/blob/master/bwislands.m
or, create isosurfaces first and then count the closed surface components using finddisconnsurf in iso2mesh.
fv=isosurface(im, 0.5);
fc=finddisconnsurf(fv.faces);
length(fc)
I'm using canny edge detection to detect the edges of a rope and eliminate the background, then using morphological filters I'm filling these edges then thinning them to be in pixel size. The plot indicates the xy coordinates of the rope. What I need to do is to get the intersection of the scattered data (blue *) with the red circle (get the coordinates of Points (1,2,3,4).
Then I need to get the whole points coordinates from the point of intersection (point1,2,3,4) to the center,grouped as A,B,C,D.
The center of the circle, the origin of the axes, and the radius are all known.
I've tried some Matlab functions to get the four intersections points like
InterX,intersections
and also I tried to manually find the intersections
idx=find(y1-y2<eps);
but no method gives me the 4 intersection points.
Thank you in Advance
You'll need a thick circle. I presume (from your previous question) that the rope points are at contiguous integer coordinates. Using a thick circle (donut) with a width of 1 ensures you'll find at least one point in each rope end. Connected component analysis will then tell you which of these points belong to the same rope end.
This question already has answers here:
Projecting 3D points to 2D plane [closed]
(2 answers)
Closed 7 years ago.
I have some points in 3d and want to add for each of them a drawing text with leader pointing at the right point in the 2d drawing view.
Problems: can't find the right 2d coordinates to point correctly at the projected points in the view because the view it's either a front view/top/side or an isometric one.
All i know : the 3d coordinates (x,y,z) and can find out some vector components of the view ( get some values like 0,0,-1 or 0,-1,-0 or some values like 0.808,0.9777,-0,332 for isometric ones ).
It is a solution based on the view vector components and 3d coordinates to do some transformations to get the 2d coordinates?
Unfortunately, generative elements in a drawing view are not exposed in the VBA api, so you cannot simply make a positional link with a drawing leader to a point from the 3d model.
Alternatively, you could, try to get you points and their XYZ coordinates from the part, and then attempt to create points and leaders using the "Arrows" collection and the Factory2D. You'll need to keep track of your views and the planes which they are projected on to make it work correctly. It's not necessarily difficult, but not straight forward either.
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...
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)));