Coordinate system

2 ビュー (過去 30 日間)
niko kauppinen
niko kauppinen 2011 年 2 月 7 日
Hi
How i can change coordinate origin to point just generated?
Example: X0=rand*10 y0=rand*10
Now i have random point(1) and i want to generate new point(2) from point(1), with random angle 2pi.Also i want certain distance from point(1) eg.2.5
I tried theta=rand*2*pi y= sin(theta) x= cos(theta) ??? i don't know how to get distance to point(2)
points are not coming around point(1) I think i have to change coordinate system center of point(1)?
Can anyone give advice

採用された回答

Walter Roberson
Walter Roberson 2011 年 2 月 7 日
To change the coordinate system, you would create a hggroup object and use makehgtform . For more information, please see here
That answers what you actually asked, but I would not recommend it in your case.
Dist = 2.5;
theta = rand*2*pi;
y = y0 + Dist * sin(theta);
x = x0 + Dist * cos(theta);

その他の回答 (2 件)

Andrew Newell
Andrew Newell 2011 年 2 月 7 日
If your object is to generate some random points in a circle around (x0,y0), you could do this:
radius = 2.5;
N = 5; % put the number of points you want here
theta = rand(N,1)*pi;
x = x0 + radius*cos(theta);
y = y0 + radius*sin(theta);

Matthew Simoneau
Matthew Simoneau 2011 年 2 月 7 日
Are you asking about transforming Cartesian to polar coordinates? If so, cart2pol will do this.
>> x0=rand*10;
>> y0=rand*10;
>> [th,r] = cart2pol(x0,y0)
th =
0.1530
r =
6.3984
I don't understand the rest about generating a new point.

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by