Draw an arc between two points --> (x1,y1,z1) and (x2,y2,z2)

조회 수: 19 (최근 30일)
Huseyin Eldem
Huseyin Eldem 2013년 2월 23일
댓글: Esther 2024년 4월 8일
Hi. I have several points on the sphere. I want to combine these points with arc. I can draw these points with lines but I can't draw arcs Please help

채택된 답변

Youssef  Khmou
Youssef Khmou 2013년 2월 23일
편집: Youssef Khmou 2013년 2월 23일
hi, you can try drawing a circle but restrict it into certain region,
I started a code, try to adjust/enhance it :
% Draw an arc between two points
p1=[-2 -2 -3];
p2=[10 15 20];
% Circle x²+y²+z²=Constant
%=> z=sqrt(Constant-x²-y²-);
Center=((p2+p1))./2;
xc=Center(1);
yc=Center(2);
zc=Center(3);
% Radius
R=norm((p2-p1))/2;
%Min=min(min(p1,p2));
%Max=max(max(p1,p2));
%x=linspace(Min,Max,20);
%y=linspace(Min,Max,20);
x=linspace(p1(1),p2(1),200);
y=linspace(p1(2),p2(2),200);
z=zc+sqrt((R^2)-((x-xc).^2)-((y-yc).^2));
figure, plot3(x,y,z), grid on, hold on
plot3(p1(1),p1(2),p1(3),'*','MarkerSize',10),
plot3(p2(1),p2(2),p2(3),'*','MarkerSize',10),
hold on, plot3(xc,yc,zc,'*','MarkerSize',10)
  댓글 수: 1
Huseyin Eldem
Huseyin Eldem 2013년 2월 24일
thanks so much. I can draw arc with above code. But I couldn't draw for several points (example 200 points). Please help me.

댓글을 달려면 로그인하십시오.

추가 답변 (5개)

Huseyin Eldem
Huseyin Eldem 2013년 2월 24일
thanks so much. I can draw arc with above code. But I couldn't draw for several points (example 200 points). Please help me.
  댓글 수: 2
Youssef  Khmou
Youssef Khmou 2013년 2월 24일
편집: Youssef Khmou 2013년 2월 24일
hi Huseyin, then you didnt have to accept the answer because the problem is not solved yet , in the code above we used circle's equation, so to draw arc between 200 points, theirs coordinates must satisfy :
1<=i,j,k <=200 xi²+yi²+zi²=R²
IF the points do not satisfy the equation they dont BELONG to the arc :
ok lets try to draw an arc between 200 points : we generalize the above code :
clear, clc
p=round(10*randn(200,3));
% Circle x²+y²+z²=Constant
%=> z=sqrt(Constant-x²-y²-);
Center=((sum(p)))./2;
xc=Center(1);
yc=Center(2);
zc=Center(3);
% Radius
p2=max(p);
p1=min(p);
R=norm((p2-p1))/2;
%Min=min(min(p1,p2));
%Max=max(max(p1,p2));
%x=linspace(Min,Max,20);
%y=linspace(Min,Max,20);
x=linspace(p1(1),p2(1),200);
y=linspace(p1(2),p2(2),200);
z=zc+sqrt((R^2)-((x-xc).^2)-((y-yc).^2));
figure, plot3(x,y,z), grid on, hold on
plot3(p(:,1),p(:,2),p(:,3),'.')
As points do not satisfy the equation the line cant contain them all .
Esther
Esther 2024년 4월 8일
Hello there can you help me with this one please y=x/(x2+1)

댓글을 달려면 로그인하십시오.


Huseyin Eldem
Huseyin Eldem 2013년 2월 24일
Hi Youssef. Sorry I shouldn't accept the answers. I dont know. Coordinates of my points satisfy this equation. My points on a unit circle that radius r=1; so
xi²+yi²+zi²= 1 my points satisfy this equation exactly...
  댓글 수: 1
Youssef  Khmou
Youssef Khmou 2013년 2월 24일
ok good, did you try the last code? it must work very well then .

댓글을 달려면 로그인하십시오.


Huseyin Eldem
Huseyin Eldem 2013년 2월 25일
didn't work :(
  댓글 수: 1
Youssef  Khmou
Youssef Khmou 2013년 2월 25일
ok can you upload the 200 points ? or copy and paste them here ?

댓글을 달려면 로그인하십시오.


ChristianW
ChristianW 2013년 2월 25일
편집: ChristianW 2013년 2월 25일
function test_sphere
n = 200;
THETA = rand(1,n)*2*pi;
PHI = rand(1,n)*2*pi;
R = 1.1*ones(1,n);
[x,y,z] = sph2cart(THETA,PHI,R);
acc = 10; % accuracy: ~ lines per arc
V = track_arc(x,y,z,acc);
plot3(x,y,z,'.r'); axis([-1 1 -1 1 -1 1]); axis square; hold on
plot3(V(1,:),V(2,:),V(3,:),'g')
sphere(31)
colormap([1 1 1]*0.1)
function V = track_arc(x,y,z,acc)
v1 = [x(1:end-1);y(1:end-1);z(1:end-1)]; % Vector from center to 1st point
v2 = [x(2:end);y(2:end);z(2:end)]; % Vector from center to 2nd point
r = sqrt(sum([x(1); y(1); z(1)].^2,1));
v3a = cross(cross(v1,v2),v1); % v3 lies in plane of v1 & v2 and is orthog. to v1
v3 = r*v3a./repmat(sqrt(sum(v3a.^2,1)),3,1); % Make v3 of length r
% Let t range through the inner angle between v1 and v2
tmax = atan2(sqrt(sum(cross(v1,v2).^2,1)),dot(v1,v2));
V = zeros(3,sum(round(tmax*acc))); % preallocate
k = 0; % index in v
for i = 1:length(tmax)
steps = round(tmax(i)*acc)+1; %Edited +1
k = (1:steps) + k(end);
t = linspace(0,tmax(i),steps);
V(:,k) = v1(:,i)*cos(t)+v3(:,i)*sin(t);
end
For the shortest great circle path, I modified code from Roger Stafford: http://www.mathworks.com/matlabcentral/newsreader/view_thread/277881

Huseyin Eldem
Huseyin Eldem 2013년 2월 25일
For Example.
X Y Z R
0,355590319 -0,825650574 -0,438014446 1
0,770249008 -0,51787671 0,372182991 1
0,389588366 0,399438725 -0,8298612 1
0,850957663 -0,515047582 -0,102941943 1
-0,600938176 -0,659250233 0,451954024 1
0,155798226 0,109555927 -0,981694663 1
-0,067669882 0,373870581 -0,92500896 1
-0,945073428 -0,286727164 -0,156919565 1
0,894045248 -0,244541832 -0,375343025 1
0,939506811 -0,210695624 -0,270063522 1
0,333053848 0,507811942 0,794482326 1
0,797502364 -0,149055451 0,584613079 1
0,959983962 -0,264782366 0,09122001 1
-0,65966674 0,060786309 0,749096 1
0,145978188 -0,446595256 -0,882747441 1
0,360864688 0,446890562 0,818575288 1
-0,574482024 0,307594985 0,758522069 1
0,440997581 -0,258061866 0,859607589 1
0,171881804 -0,632864183 0,754943422 1
0,948105757 -0,246657847 0,200637433 1
-0,462783426 -0,687829262 0,559215887 1
0,232416051 0,053043441 -0,971168972 1
0,569384383 -0,79277486 0,217507347 1
0,502037406 -0,221031767 0,836124034 1
-0,127461455 -0,265374445 -0,955682992 1
0,003090819 -0,06350426 -0,997976781 1
-0,042343557 -0,980702139 0,190867329 1
-0,266574407 0,214318097 0,939683904 1
-0,405592374 -0,600682924 0,68896651 1
0,455800865 0,843943692 0,282850874 1
-0,260645438 -0,919667152 -0,29372825 1
0,719080503 0,145773573 0,679465448 1
-0,15964546 0,934723257 -0,317499229 1
0,754889146 0,225353585 -0,615920562 1
0,525811885 0,367732329 0,767003778 1
0,160574483 -0,322840865 0,932732336 1
-0,272763785 -0,755078476 0,596201655 1
-0,344671309 0,768513045 0,539063437 1
0,924612456 -0,29899926 0,235989935 1
0,976372458 0,214679929 -0,024685022 1
-0,246017293 0,099657412 0,964128566 1
-0,540166724 0,497386991 0,678841728 1
0,056963988 -0,582424454 -0,810886465 1
0,025685475 -0,087997291 0,995789502 1
0,085630278 0,204446505 -0,975125162 1
-0,747873978 0,04816384 -0,662091201 1
-0,941518833 0,335055515 0,035778327 1
-0,588009865 -0,771110351 -0,244199151 1
-0,171307305 -0,656312797 0,734783859 1
0,029197332 -0,991225023 0,128920402 1
-0,01883528 0,114157646 -0,99328408 1
-0,422855825 -0,89427415 -0,146515173 1
-0,560336444 -0,825603151 -0,066351389 1
0,347095121 0,567301365 0,74678922 1
0,732819277 0,679529154 0,034871695 1
-0,924956632 0,009507931 -0,379953718 1
0,818868822 -0,211654566 -0,533531814 1
-0,509153711 0,79801628 0,322385663 1
-0,786387246 -0,466855572 0,404525617 1
0,006183017 0,03723684 -0,99928734 1
0,000941658 -0,118278835 0,992979975 1
-0,011298248 0,352800191 -0,935630469 1
-0,26887209 -0,010068385 -0,963123267 1
-0,187912764 -0,567120412 -0,801912234 1
0,236235372 -0,193183166 0,952298857 1
0,709133615 -0,185443709 0,680250063 1
-0,831217773 -0,254090558 0,494484582 1
0,544092217 0,64624014 -0,535104981 1
0,24598342 0,335428005 0,909384523 1
-0,036219871 0,767194913 -0,640390573 1
0,177617534 -0,2771121 0,944277976 1
-0,023824448 0,885265118 -0,464476121 1
0,39295407 -0,919375947 0,018302096 1
0,026018937 0,639187245 -0,768610877 1
0,70454379 -0,335523451 -0,625333561 1
-0,175064729 0,24100762 -0,954603409 1
0,110644762 0,317270008 -0,941858524 1
-0,005906513 0,867305668 0,497740887 1
-0,605050212 -0,540523029 -0,584593103 1
-0,574024499 0,097254016 0,813042146 1
-0,057114923 0,076912538 0,995400596 1
0,350214448 -0,629254956 -0,693821332 1
-0,859896171 -0,510468971 -7,05E-05 1
-0,949699335 -0,306753661 0,063034636 1
0,255855389 -0,146590738 -0,955536067 1
-0,210116171 0,917264804 -0,338343721 1
0,042170011 -0,931496233 -0,361298294 1
0,010012473 -0,427246634 -0,904079678 1
-0,419341879 0,391583399 -0,819032862 1
-0,884248083 -0,401406601 -0,238700793 1
0,482980446 0,249365339 0,839372871 1
0,645445957 0,227576549 0,729114827 1
-0,342513349 -0,067118485 -0,937112434 1
0,016394353 -0,088454263 0,995945314 1
0,914807638 -0,402642275 0,031720402 1
0,344834644 0,366778212 0,864038663 1
-0,060766006 -0,028047621 -0,997757898 1
-0,770466341 0,150033806 -0,619573624 1
0,997203967 0,074713142 -0,00148165 1
-0,518330052 0,850356862 0,090703715 1
0,09760858 0,158571362 0,98251091 1
0,230996571 -0,808646216 -0,541047023 1
-0,04986827 0,123196615 0,991128523 1
-0,219005396 -0,039689194 0,974916101 1
0,50435989 0,860814842 -0,067962558 1
-0,23987377 -0,178884326 0,954180786 1
-0,044021151 0,538933851 -0,84119703 1
-0,307417731 -0,446768767 -0,840173796 1
-0,285347906 -0,710442163 -0,643310583 1
-0,0052681 -0,453583217 0,891198358 1
-0,834902034 0,268138484 -0,480666566 1
0,863013427 0,501795849 -0,058384514 1
0,01116895 0,084062236 -0,99639791 1
0,763373354 -0,46228893 -0,451165233 1
0,337864258 0,479949869 -0,809626992 1
0,453736216 -0,879319521 0,144639646 1
-0,949297751 -0,233227457 0,210804963 1
0,521503928 -0,012667887 -0,853154838 1
0,228584446 0,122274253 0,965814764 1
-0,380204133 0,143180701 0,913752759 1
0,40611889 0,321828134 0,855274283 1
0,915012486 -0,223338414 0,335964438 1
0,505091488 0,014711255 -0,86294042 1
0,090285256 -0,572121584 -0,815184314 1
0,077495522 -0,172200915 0,982008803 1
0,64484451 -0,698075264 0,311233809 1
0,859468343 0,504184664 -0,084332628 1
-0,780761524 0,568887158 0,258416031 1
-0,05460348 0,879322706 -0,473085657 1
0,28475396 -0,875101203 -0,391296647 1
-0,721371123 0,331656709 0,607970008 1
0,827061457 -0,52016068 0,213077952 1
0,02019571 0,044243655 0,998816616 1
-0,004334724 0,049856289 -0,998746995 1
0,305946474 0,397194017 0,865236192 1
0,214945282 0,247132782 0,944840682 1
0,627295276 -0,673983195 0,390188787 1
-0,511400863 -0,279910149 0,812477363 1
-0,950828379 -0,308019772 0,032391574 1
0,536820407 0,691658988 0,483147696 1
0,09129101 -0,120746884 -0,988476677 1
-0,178346176 -0,171865417 -0,968842051 1
-0,097624767 0,132691875 0,986337808 1
-0,731017924 -0,06099772 -0,679626421 1
-0,610327582 0,432921845 0,663384442 1
0,862260792 0,445961352 0,240051658 1
0,062601617 0,98672875 -0,149824604 1
0,127850711 0,12517801 -0,983862115 1
0,390041078 0,884625999 0,255548035 1
0,003357372 0,053111085 -0,998582966 1
-0,704474707 0,403192895 0,584081225 1
0,76802631 0,24770452 -0,590574345 1
0,709635274 -0,497301854 -0,499107849 1
0,933331392 -0,337430397 -0,122610114 1
-0,811162706 0,046614058 -0,582959857 1
-0,864268997 0,058450939 -0,499622447 1
-0,277999348 0,452253041 0,847457108 1
0,316739446 -0,22996099 0,920214141 1
-0,001967682 0,002115342 -0,999995827 1
0,392078574 0,329377897 0,858943882 1
0,019316813 -0,100398127 0,994759809 1
-0,755288038 0,626919029 -0,191082471 1
0,018924462 0,362172157 -0,931919092 1
-0,709662807 0,489410543 -0,50680965 1
0,462906359 0,320814076 0,826314729 1
0,61898671 0,675751324 0,400269411 1
0,927338518 -0,353407664 0,123070294 1
0,055478113 -0,015689903 -0,99833662 1
-0,420118936 -0,21475533 0,881691685 1
0,40789635 0,160844371 -0,898748939 1
0,085779152 0,89424808 -0,439274752 1
-0,558687286 0,737724015 0,378987855 1
0,244169456 -0,508940251 0,825445999 1
0,970143405 0,094187317 0,223496135 1
0,962147125 0,266620297 0,056449338 1
0,180259116 0,323017556 0,929067441 1
-0,56901041 -0,774091835 -0,277504927 1
-0,074744441 -0,647984142 0,757977454 1
-0,560248942 -0,748588197 0,354593902 1
-0,920635191 0,293236263 -0,257766054 1
-0,68031362 -0,206996033 0,703083225 1
-0,226978839 0,757737399 0,611812586 1
-0,031109524 -0,932583255 -0,359611832 1
0,277007889 0,686439582 0,672359524 1
-0,20279312 -0,483350164 -0,851614684 1
0,022086194 0,049755942 -0,998517174 1
-0,507906321 0,551291456 -0,661897953 1
-0,621316542 -0,626164943 0,471044817 1
0,182238677 -0,94796679 -0,261051777 1
0,289913195 0,16206205 0,943231801 1
0,262020733 -0,124534583 -0,956993351 1
0,059377576 -0,364328891 -0,929375469 1
-0,5398891 0,044908882 -0,8405373 1
-0,672004815 0,286508316 0,68287811 1
-0,903419216 0,313858849 -0,292106731 1
-0,024500295 0,06628335 0,997500002 1
-0,971170262 -0,0519697 0,232653118 1
-0,829947015 -0,056256514 0,554998339 1
0,200283695 -0,442631879 0,874050034 1
0,148034944 -0,511561538 0,846398516 1
  댓글 수: 1
Youssef  Khmou
Youssef Khmou 2013년 2월 25일
hi, they numbers need more processing to convert them into Mat format, anyway try this with numbers :
X=reshape(x,20,10);
Y=reshape(y,20,10);
Z=reshape(z,20,10);
figure, surf(X,Y,Z), shading interp
If they satisfy the equation, them they must give a partial Sphere
...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by