How to define random points above and below a define line within a specific range
20 views (last 30 days)
Show older comments
Santosh Prakash
on 16 Apr 2017
Commented: Santosh Prakash
on 24 Apr 2017
- Suppose line equation is given by y=mx+c and i have a random set of values of x
- Then we can get corresponding values of y
- Now with the line defined I would like to define random points above and below the line and within a specific range
3 Comments
Accepted Answer
Image Analyst
on 16 Apr 2017
Edited: Image Analyst
on 16 Apr 2017
Do you just want to add uniformly distributed noise, like
y = y + amplitude * rand(1, length(y));
7 Comments
Image Analyst
on 17 Apr 2017
I think the code, as-is, should do the job. I don't think tilting the random locations would lead to a substantially different random arrangement.
More Answers (1)
Roger Stafford
on 17 Apr 2017
Let w be the allowed perpendicular distance of random points on either side of the line segment. Let x1 be the x-coordinate of left end of segment and d be the segment’s length. Let N be the desired number of random points.
a = atan(m);
x = d*cos(a)*rand(N,1)+x1;
y = m*x+c;
h = 2*w*rand(N,1)-w;
x = x - h*sin(a);
y = y + h*cos(a);
X = [x1,x1+d*cos(a)];
Y = m*X+c;
plot(x,y,'y.',X,Y,'r-',X,Y,'r*')
axis equal
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!