how to move points by steps to the centre and how to change the direction
4 views (last 30 days)
Show older comments
Dear,
I have these points and a point call centre. I want to accumulate the points around the centre.
x=[ 24.5270 27.5315
29.9260 26.9389
23.9923 21.3688
20.6191 29.0696
22.9296 23.7888
25.5227 25.2962
27.4013 29.8862
23.1840 29.5821
24.9386 28.1765
26.2867 24.2390];
the centre=[ 31.5618 27.1874];
the distance between the points and the centre
dis=[ 7.0433,1.6546,9.5474,11.1034, 9.2771, 6.3283,4.9592,8.7133,6.6967,6.0432]';
I took the half maximum distance and compared others with it if the distance of the point larger then move it to the centre using a step, if not the just move it in small direction around the centre. I wrote this code but it doesn't help, it push some points far from the centre, see the code
%let x=one point
dis;
maxdis=max(dis);
maxdis=maxdis/2;
% for each point separately
% just move the point around the centre a little
if dis<maxdis
ra=2*rand;
newp= x*ra
else
% push the point towards the centre
step=0.5;
newp= x+step;
end
in fact I don't know how to direct the points to the centre, I may have the points in any place around the centre so how I'm going to deal with them.
I appreciate any help
Nadia,
2 Comments
jgg
on 18 Dec 2015
Is this the entire code you've written or is it pseudocode? It doesn't seem to be indexed by point nor are you looping.
It also doesn't seem to do what you want:
if dis<maxdis
ra=2*rand;
newp= x*ra
This says that if the distance of the point from the centre is less than the maximum distance, you sample a random number in [0,2] the multiply the point by the random number. If rand > 1 this will move points away from the center.
else
% push the point towards the centre
step=0.5;
newp= x+step;
end
This also does not move the points towards the centre. It says if the point is the furthest from the center, move it 0.5 units away in each direction.
I think you need to rework your algorithm, or post what you're actually doing.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!