You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Problems encountered when using sph2cart
    5 views (last 30 days)
  
       Show older comments
    
Here is the code:
load angles.mat
load vertices.mat
[vectors(:,1), vectors(:,2), vectors(:,3)] = sph2cart(angle_phi_theta(:,1), angle_phi_theta(:,2), 1);
quiver3(vertex_segment(:,1),vertex_segment(:,2),vertex_segment(:,3),...
    vectors(:,1),vectors(:,2),vectors(:,3),0.8,'Color','green','LineWidth',1);hold on;
The results:

Problem: I think the resulting vectors should converge uniformly or diverge uniformly, but why do they alternate like this? What went wrong?
Accepted Answer
  Star Strider
      
      
 on 15 Apr 2025
        
      Edited: Star Strider
      
      
 on 15 Apr 2025
  
      Your data do not vary much.  Also, what are the uints for ‘angle_phi_theta’ ?  They appear to be more like degrees than radians that all MATLAB trigonometric functions (except those ending in ‘d’ such as sind) require.  Using the deg2rad function produces a smooth, continuous surface for ‘vectors’, and a different result for the quiver plot.  I am not sure that is an improvement, or the result you want.  
load angles.mat
load vertices.mat
whos
format long
angle_phi_theta
vertex_segment
angle_phi_theta = deg2rad(angle_phi_theta)
[vectors(:,1), vectors(:,2), vectors(:,3)] = sph2cart(angle_phi_theta(:,1), angle_phi_theta(:,2), 1);
figure
surf(vectors, EdgeColor='interp')
grid on
colormap(turbo)
figure
quiver3(vertex_segment(:,1),vertex_segment(:,2),vertex_segment(:,3),...
        vectors(:,1),vectors(:,2),vectors(:,3),0.8,'Color','green','LineWidth',1);hold on;
.
4 Comments
  bird
 on 15 Apr 2025
				Thank you very much for your answer. The values in angle_phi_theta are in radians, which does not need to be transformed. The first column roughly covers the range of 2*pi, so the problem you mentioned does not exist. The ideal result should be a cluster of vectors that "converge" all point to the Z-axis, as shown in the figure below, but in the opposite direction

  Star Strider
      
      
 on 15 Apr 2025
				The first column of ‘angle_phi_theta’ goes from -9 to -2, and I thought that was a bit unusual for radian measure although the difference spans about  radians.  The ‘vectors’ array, controlling the dirrection and magnitude of the arrows, is a spiral.
radians.  The ‘vectors’ array, controlling the dirrection and magnitude of the arrows, is a spiral.  
 radians.  The ‘vectors’ array, controlling the dirrection and magnitude of the arrows, is a spiral.
radians.  The ‘vectors’ array, controlling the dirrection and magnitude of the arrows, is a spiral.  I am not certain that it is even possible to get the result you want.  I attenpted a few experiments to see if I could come up with a result that resembles the one you want, and failed.  
load angles.mat
load vertices.mat
whos
  Name                   Size            Bytes  Class     Attributes
  angle_phi_theta      375x2              6000  double              
  ans                    1x36               72  char                
  vertex_segment       375x3              9000  double              
format long
disp(angle_phi_theta)
  -9.148764617364000   0.407847307973360
  -9.123309592460078   0.407853188681914
  -9.101024233864036   0.407858337123113
  -9.092495752495266   0.407860307402597
  -9.083035544599770   0.407862492932790
  -9.062827352976990   0.407867161499636
  -9.036664952651956   0.407873205628524
  -9.031272314098036   0.407874451454674
  -8.997910473048979   0.407882158823446
  -8.993195935993631   0.407883247992225
  -8.962640096238994   0.407890307108800
  -8.956060817311968   0.407891827076744
  -8.924364085619564   0.407899149766150
  -8.919331643379326   0.407900312378492
  -8.891445453873439   0.407906754743164
  -8.886032015482957   0.407908005374564
  -8.884957445715688   0.407908253625416
  -8.851474343921398   0.407915989008268
  -8.844455912489124   0.407917610430754
  -8.812759955659198   0.407924932941148
  -8.808878385768500   0.407925829674950
  -8.774376793402221   0.407933800353043
  -8.773327391647955   0.407934042789493
  -8.757494279067208   0.407937700610333
  -8.731977591937422   0.407943595564310
  -8.730251910441597   0.407943994237262
  -8.691265708648416   0.407953000965451
  -8.686407991646309   0.407954123212161
  -8.657811141828294   0.407960729756054
  -8.644716231267585   0.407963754987922
  -8.624892502853193   0.407968334734738
  -8.603998172896079   0.407973161815653
  -8.594059437573584   0.407975457896920
  -8.560236835076172   0.407983271712407
  -8.559347626570311   0.407983477140455
  -8.556705261678232   0.407984087588800
  -8.527795054947743   0.407990766525499
  -8.515260390476945   0.407993662327363
  -8.492534598569263   0.407998912519000
  -8.462737612243885   0.408005796322611
  -8.459885683792100   0.408006455185060
  -8.455655012602099   0.408007432569461
  -8.425368441091587   0.408014429478747
  -8.403673078357528   0.408019441617046
  -8.393960090440599   0.408021685545360
  -8.381705112560315   0.408024516733054
  -8.360925692608937   0.408029317267059
  -8.343889450026978   0.408033253039185
  -8.329489588903082   0.408036579745279
  -8.313174746078337   0.408040348857119
  -8.295924568658416   0.408044334053217
  -8.282993685274077   0.408047321390955
  -8.265912042568493   0.408051267651576
  -8.244116231684254   0.408056302995756
  -8.234314405163801   0.408058567447874
  -8.224450540212102   0.408060846232327
  -8.205421556276088   0.408065242374504
  -8.189974033661258   0.408068811115007
  -8.173870326050665   0.408072531449654
  -8.144792640971588   0.408079249077785
  -8.144182408096921   0.408079390055910
  -8.143138555459009   0.408079631210384
  -8.110601361485180   0.408087148066315
  -8.096504191555194   0.408090404843635
  -8.068422160661958   0.408096892452267
  -8.061703269300365   0.408098444673962
  -8.054011445190904   0.408100221665970
  -8.037730210686496   0.408103983013499
  -8.009679112433922   0.408110463475964
  -8.009471790406328   0.408110511372221
  -8.009247502542886   0.408110563187985
  -7.966262633975288   0.408120493702107
  -7.962031545077350   0.408121471183007
  -7.953113379869479   0.408123531488610
  -7.924904897652661   0.408130048310467
  -7.908321297474928   0.408133879511567
  -7.896109288287457   0.408136700772484
  -7.878241347703791   0.408140828686380
  -7.868072253962969   0.408143177985851
  -7.847832857072452   0.408147853761847
  -7.841012865177436   0.408149429340139
  -7.839153546016472   0.408149858886531
  -7.809500473886591   0.408156709442583
  -7.795244981123580   0.408160002796196
  -7.776212238451611   0.408164399806730
  -7.750583672782322   0.408170320607276
  -7.742659676125418   0.408172151236595
  -7.721171467309741   0.408177115517474
  -7.709851889019490   0.408179730605895
  -7.705998549110644   0.408180620817908
  -7.680900435862632   0.408186419071487
  -7.649535188502819   0.408193665180227
  -7.646728415028743   0.408194313610816
  -7.639092949579625   0.408196077582650
  -7.612186649991633   0.408202293569739
  -7.605174913844088   0.408203913445457
  -7.574565057442980   0.408210985041146
  -7.559495839774503   0.408214466384322
  -7.538818086185089   0.408219243431009
  -7.519925103790892   0.408223608153637
  -7.497378985925581   0.408228816836350
  -7.477261993844277   0.408233464333960
  -7.458163136660533   0.408237876618499
  -7.438929154903955   0.408242320119987
  -7.420149710992973   0.408246658612558
  -7.398273421129744   0.408251712549272
  -7.382448190285806   0.408255368549246
  -7.361564494321554   0.408260193173459
  -7.344155465924048   0.408264215067863
  -7.321237932574727   0.408269509556276
  -7.304464177183431   0.408273384687696
  -7.284182833123062   0.408278070154473
  -7.262380459195342   0.408283107014871
  -7.244786776298693   0.408287171568800
  -7.218058823664437   0.408293346353554
  -7.212359482739743   0.408294663035154
  -7.199661842212128   0.408297596488315
  -7.175200844933570   0.408303247553143
  -7.167953644436715   0.408304921826656
  -7.139217039970933   0.408311560657155
  -7.125940757758935   0.408314627790134
  -7.099554311175555   0.408320723678970
  -7.084735256818208   0.408324147228546
  -7.062938901604910   0.408329182698479
  -7.044165952110047   0.408333519690687
  -7.022374576621583   0.408338554010187
  -7.002369167410005   0.408343175729534
  -6.994267840687920   0.408345047326263
  -6.966923458673351   0.408351364520680
  -6.959406930917171   0.408353101015114
  -6.930413564785653   0.408359799163588
  -6.918558099627483   0.408362538054461
  -6.896167965707019   0.408367710701219
  -6.866279361019279   0.408374615670824
  -6.859800259639593   0.408376112495402
  -6.851109313969824   0.408378120307955
  -6.828131535132552   0.408383428714490
  -6.810260876750594   0.408387557256262
  -6.793828867611346   0.408391353436272
  -6.771696717173461   0.408396466482788
  -6.762340391986884   0.408398628013636
  -6.756581121895988   0.408399958540281
  -6.728438615509809   0.408406460120171
  -6.704517589362084   0.408411986438987
  -6.697647920260055   0.408413573493881
  -6.686493357911860   0.408416150459744
  -6.664598210206873   0.408421208753063
  -6.650116451894551   0.408424554379331
  -6.634191671593553   0.408428233377568
  -6.609602713609120   0.408433914004324
  -6.600632277373491   0.408435986385761
  -6.595035103812488   0.408437279464301
  -6.569280032288525   0.408443229490671
  -6.541251989931666   0.408449704626683
  -6.535198122202363   0.408451103212301
  -6.526831850560040   0.408453036017529
  -6.504009431486232   0.408458308532310
  -6.484874473965397   0.408462729156874
  -6.469820813338164   0.408466206906008
  -6.457861842271789   0.408468969709176
  -6.438456005088360   0.408473452913304
  -6.406943212714915   0.408480733108407
  -6.404573419488739   0.408481280586296
  -6.403024893967402   0.408481638332058
  -6.373777157437251   0.408488395246068
  -6.351981179288222   0.408493430628890
  -6.340802147343534   0.408496013247804
  -6.322743998090528   0.408500185104370
  -6.310817522727850   0.408502940400267
  -6.304436910867977   0.408504414471453
  -6.278561282006474   0.408510392349399
  -6.257742435887128   0.408515201991775
  -6.249053935700081   0.408517209239364
  -6.232774990238909   0.408520970058070
  -6.217920114458816   0.408524401883236
  -6.208061959870466   0.408526679348461
  -6.189304333521725   0.408531012800662
  -6.166334976784953   0.408536319261495
  -6.158170612527804   0.408538205421375
  -6.151477268996635   0.408539751740921
  -6.129066888347361   0.408544929065150
  -6.101231223008939   0.408551359757552
  -6.094279332511249   0.408552965807520
  -6.069280368532015   0.408558741155290
  -6.057240253195362   0.408561522704690
  -6.054475039791175   0.408562161533926
  -6.035601275098351   0.408566521816813
  -6.013314133943346   0.408571670669824
  -6.008999833846802   0.408572667374466
  -5.978884425325694   0.408579624741083
  -5.963990412382647   0.408583065607852
  -5.946307132274825   0.408587150860842
  -5.918785153986386   0.408593509084169
  -5.915774876517690   0.408594204528960
  -5.913359090646521   0.408594762632230
  -5.888310440497629   0.408600549458672
  -5.867677267801326   0.408605316206126
  -5.855760221536546   0.408608069323680
  -5.823536664961541   0.408615513722006
  -5.820893878093504   0.408616124267838
  -5.783874007087557   0.408624676727437
  -5.783300707624328   0.408624809173077
  -5.757343590832400   0.408630805876648
  -5.741191969576696   0.408634537280472
  -5.716261232527298   0.408640296866219
  -5.694165320693126   0.408645401540766
  -5.676391038302368   0.408649507817420
  -5.653309953367502   0.408654840090090
  -5.652152058224631   0.408655107591061
  -5.619201304433556   0.408662719989022
  -5.615804151979209   0.408663504811020
  -5.585318565788254   0.408670547697372
  -5.580087464358490   0.408671756204652
  -5.548618481234389   0.408679026278790
  -5.540313241898680   0.408680944984122
  -5.514671294678698   0.408686868876121
  -5.498762802262527   0.408690544111473
  -5.479336245592483   0.408695032102289
  -5.458257559667610   0.408699901773762
  -5.446823745601422   0.408702543253330
  -5.420789033194835   0.408708557883311
  -5.411717976836525   0.408710653510360
  -5.388307995513657   0.408716061765819
  -5.378010710624968   0.408718440680456
  -5.351283082155533   0.408724615390320
  -5.340348225120673   0.408727141599096
  -5.313388576656070   0.408733369911028
  -5.307445459647942   0.408734742910628
  -5.271761775133259   0.408742986679768
  -5.271335659576360   0.408743085122469
  -5.258696887047570   0.408746004975740
  -5.237313898488557   0.408750944948268
  -5.236633507300160   0.408751102134611
  -5.222369133326472   0.408754397539992
  -5.201353410117251   0.408759252665599
  -5.200380277416604   0.408759477482106
  -5.168073935172862   0.408766941005866
  -5.165819182490160   0.408767461906688
  -5.131828372412661   0.408775314582076
  -5.128211299383798   0.408776150210891
  -5.099176367309159   0.408782857962074
  -5.091675763250121   0.408784590777761
  -5.063131803848165   0.408791185102726
  -5.048025191476036   0.408794675084957
  -5.027820323925906   0.408799342883864
  -5.005974027611199   0.408804389891364
  -4.994534117620404   0.408807032779234
  -4.973979211496878   0.408811781445272
  -4.963278025272235   0.408814253670603
  -4.955605757465920   0.408816026144646
  -4.935625438382537   0.408820642067584
  -4.919708317460247   0.408824319296324
  -4.901233297902175   0.408828587459721
  -4.878636054750873   0.408833807953576
  -4.864070851011079   0.408837172857698
  -4.847359459184210   0.408841033581670
  -4.828101295929122   0.408845482669652
  -4.800892445978530   0.408851768552980
  -4.788546035681099   0.408854620863709
  -4.762721362515179   0.408860586969692
  -4.747721309151140   0.408864052334290
  -4.731713580497001   0.408867750495544
  -4.706293975233895   0.408873623021329
  -4.703337595805679   0.408874306014406
  -4.699292639781260   0.408875240494242
  -4.670165650705438   0.408881969512754
  -4.658210086045617   0.408884731528962
  -4.635116210491826   0.408890066756565
  -4.616839718284542   0.408894289055481
  -4.603319462414841   0.408897412552105
  -4.577452607503858   0.408903388403062
  -4.572470835439445   0.408904539309404
  -4.548001577133141   0.408910192282723
  -4.544756718035495   0.408910941921379
  -4.515784279703881   0.408917635235040
  -4.508556474728540   0.408919305027731
  -4.480193630370923   0.408925857510868
  -4.472136481096904   0.408927718901569
  -4.443055978527489   0.408934437180606
  -4.434370106177877   0.408936443821103
  -4.408470977734429   0.408942427128004
  -4.402909502593193   0.408943711959371
  -4.371380921452699   0.408950995802051
  -4.370670785090422   0.408951159860227
  -4.352895448199074   0.408955266380496
  -4.338993181459015   0.408958478130602
  -4.338441138235428   0.408958605665551
  -4.311828263183580   0.408964753864681
  -4.301046951254461   0.408967244600931
  -4.300829707084896   0.408967294789436
  -4.299904722091399   0.408967508482693
  -4.264265467750263   0.408975741987419
  -4.253722971038284   0.408978177551746
  -4.232949320977738   0.408982976752771
  -4.209310863160264   0.408988437791666
  -4.204080214093326   0.408989646194440
  -4.196606731966723   0.408991372744323
  -4.174117933397191   0.408996568184933
  -4.149367253800408   0.409002286173180
  -4.145735195530893   0.409003125263938
  -4.143113045352598   0.409003731042209
  -4.113929493225353   0.409010473128114
  -4.093568426148043   0.409015177012781
  -4.079197928599575   0.409018496935200
  -4.054935827775687   0.409024102050276
  -4.041550388720443   0.409027194401049
  -4.019600998438277   0.409032265225677
  -4.003023465011813   0.409036095025215
  -3.980685242345301   0.409041255679255
  -3.961702667916190   0.409045641099747
  -3.943534612673187   0.409049838347177
  -3.920370262704429   0.409055189856025
  -3.903858349111077   0.409059004495841
  -3.883041796431847   0.409063813608378
  -3.867256768640527   0.409067460320503
  -3.843350854572820   0.409072983148073
  -3.827575009312034   0.409076627738818
  -3.806755642332250   0.409081437501525
  -3.791667892901591   0.409084923125973
  -3.765343247749146   0.409091004737227
  -3.753246855050296   0.409093799288019
  -3.726375929837273   0.409100007102796
  -3.723094425065367   0.409100765207464
  -3.717625397639025   0.409102028681237
  -3.689918170312566   0.409108429701443
  -3.680769466384305   0.409110543266904
  -3.655606844267533   0.409116356423547
  -3.632564579450348   0.409121679727858
  -3.619336267838975   0.409124735778502
  -3.587710795301275   0.409132042005369
  -3.583406238542361   0.409133036459071
  -3.544749839968377   0.409141966994972
  -3.544451893522377   0.409142035827598
  -3.543491162656882   0.409142257778990
  -3.520252270862667   0.409147626508751
  -3.503196332956179   0.409151566830959
  -3.493785632323887   0.409153740923812
  -3.466038294800765   0.409160151210415
  -3.453451630149551   0.409163059025542
  -3.429788230478575   0.409168525826591
  -3.421627745323971   0.409170411090308
  -3.396285176996253   0.409176265818751
  -3.369355754730348   0.409182487147721
  -3.362890770400346   0.409183980710929
  -3.355803018561176   0.409185618148057
  -3.328515979704230   0.409191922094858
  -3.301805171242961   0.409198092918905
  -3.294656921425863   0.409199744332487
  -3.285671382143423   0.409201820203083
  -3.258711420785469   0.409208048587300
  -3.236301906849635   0.409213225711298
  -3.227772291306884   0.409215196252803
  -3.217114027089362   0.409217658562142
  -3.195502284684051   0.409222651382181
  -3.185501029788516   0.409224961906937
  -3.162619111740860   0.409230248167379
  -3.133638446179734   0.409236943381723
  -3.125685553502730   0.409238780686702
  -3.113479051978757   0.409241600675218
  -3.094364898693318   0.409246016493516
  -3.081700429232153   0.409248942283381
  -3.061727447640713   0.409253556511186
  -3.040311274568057   0.409258504150116
  -3.031994750581490   0.409260425462467
  -3.024066311686054   0.409262257118048
  -2.999222351672359   0.409267996656262
  -2.969619241780254   0.409274835669864
  -2.969106526818756   0.409274954119061
  -2.968480781296805   0.409275098680972
  -2.935249929730674   0.409282775788097
  -2.914387670231465   0.409287595459983
  -2.903521880759310   0.409290105712530
  -2.883689325518748   0.409294687498550
  -2.870278228707041   0.409297785776868
  -2.863742239939910   0.409299295743768
figure
plot(angle_phi_theta(:,1), angle_phi_theta(:,2))
grid

disp(vertex_segment)
  24.276068429529410  -0.448447928746336  81.067888845006465
  24.259140628673865  -1.111978356700450  81.053336662519229
  24.230347879342876  -1.686194075643361  81.035379587412891
  24.222789097806036  -1.838657154480922  81.017396569952453
  24.205319637130444  -2.010328693931287  81.065814520761450
  24.154085264800283  -2.518686225537345  81.100737089879914
  24.071652394713709  -3.188041341858980  81.134735008918099
  24.062239752877428  -3.256346875155522  81.164042492094680
  23.921659335817342  -4.142426303775671  81.159891955460267
  23.910847013653022  -4.207351211131320  81.151844177732812
  23.757607162813986  -5.021413694494438  81.132784324134050
  23.743249569271679  -5.100996054378162  81.095281969014735
  23.566597628880228  -5.850897212088218  81.098242292837853
  23.548254286281303  -5.916977061595144  81.143171986441047
  23.346233651334085  -6.675944104164344  81.051805258223496
  23.320733839914578  -6.783375420029976  80.946290290919151
  23.336806556320248  -6.724576201496944  80.972303529872207
  23.071177938945290  -7.559883529001964  80.998483050425520
  23.032008532020487  -7.676669625671794  81.000201874769488
  22.757058145615851  -8.457364217588633  80.989979098579838
  22.751035398334285  -8.475065860537281  80.970138247022390
  22.407589012090202  -9.342875320783318  80.960851644113035
  22.427293498989883  -9.296061578995973  80.956050254236587
  22.256714806691424  -9.679250219521046  81.040480496501161
  21.982813729090424 -10.302493781356794  81.129667716973970
  21.996471955238441 -10.272077200941681  81.138770064915533
  21.550091381914925 -11.209116736253282  81.155098356896914
  21.536936654409669 -11.233300503121656  81.154434024807330
  21.193832075739966 -11.876463628268949  81.143260583453568
  21.069779760405140 -12.093468886204336  81.103837706203450
  20.820370440725188 -12.508032453666791  81.049080646673303
  20.534486354778700 -12.965825233668724  81.025163978636300
  20.412469229153654 -13.156830486232742  80.998861238704123
  19.904475514038086 -13.925999700027681  80.964961365811888
  19.938249858303962 -13.879944733560247  80.931311145378530
  19.925888953254717 -13.891499214227371  80.995076454847521
  19.471335677306747 -14.518230250744327  81.061470462658093
  19.299491892122319 -14.746469786508822  81.034486075344915
  18.963038276798613 -15.185357424460260  81.007464382615026
  18.486386112976497 -15.762075630544199  80.962928354748641
  18.491210029625073 -15.760612644053303  80.915330490031366
  18.465138296115590 -15.783210449309657  81.001331976684938
  17.911281194009469 -16.382325471714502  81.082377223878140
  17.515953917730130 -16.803146659145014  81.044606968754039
  17.361201766307147 -16.966136091282941  81.005864541054095
  17.145637932398657 -17.182181505406305  81.041771170172581
  16.760103404683733 -17.565060300345465  81.076638189137142
  16.460545826429986 -17.855074234256474  81.019684341549237
  16.210970325645700 -18.091304158029025  80.963817328817427
  15.907223982396950 -18.361752756083209  81.019973401445910
  15.610771016591169 -18.621319649439922  81.075630985002491
  15.400750182818134 -18.794956721184644  81.044922839182817
  15.079846282683203 -19.056232394797945  81.016940329279848
  14.641466554279155 -19.390145348336358  81.066855071083694
  14.474121739450164 -19.514787071695551  81.111487227242307
  14.300466447777062 -19.640795749505003  81.072058683089566
  13.909023035035393 -19.919652833298983  81.032757559612833
  13.600236919953945 -20.125907150875147  81.067169847802049
  13.274277395916990 -20.339942045750611  81.101822416828256
  12.613479623220975 -20.753806632575344  81.117676449440836
  12.621728666813262 -20.748235432060966  81.134810213006460
  12.649823078648833 -20.734943820379847  81.034336819912085
  11.953930530150997 -21.146910783470986  80.969114633866369
  11.700702210565726 -21.280548591002557  80.987460595893126
  11.043724410784966 -21.620002323657769  81.027401597830618
  10.902200767326010 -21.687217763496484  81.085151423066506
  10.711996464450779 -21.783603643067163  81.051055319785505
  10.371067279811180 -21.952337725058818  81.012045913071901
   9.691652348454289 -22.258983214035048  81.011912025098454
   9.705849518186438 -22.252877377786298  81.007106740709702
   9.771430493634842 -22.221203003351214  81.072467873463552
   8.767863319592895 -22.636692604923837  81.078626832343389
   8.733388336538905 -22.651446149815929  81.001981359543493
   8.481583379537348 -22.743582212399630  81.038407740135995
   7.780958940296807 -22.997406262659428  81.094711846377876
   7.419350877550599 -23.120685661990731  81.049932655829068
   7.129107377253721 -23.215475132364716  80.997908924906639
   6.676131693661377 -23.354294527049504  81.082123391940883
   6.506606839735163 -23.403318444466137  81.159159932264373
   6.035856485388052 -23.528714947855129  81.047978995389954
   5.884877119941381 -23.572169180428606  80.938413964650479
   5.891132690399468 -23.569210577176911  80.965518581505521
   5.127672411930455 -23.740715722849501  80.984942714300146
   4.804482282272348 -23.806401766618478  81.011220732643110
   4.324549592168333 -23.895641466368211  81.048016940925052
   3.662219300065045 -24.012436540757463  81.097034759908610
   3.505679550233745 -24.035710329138350  81.143463266300785
   2.920462953026593 -24.124154932427501  81.080331014936164
   2.725244571880698 -24.157076725904155  80.990848843239732
   2.724564716375938 -24.157819945063348  80.952767974446559
   2.085178221613884 -24.221073335019280  80.944767941884024
   1.269064430595823 -24.266713801973495  80.941528404023643
   1.265921432084268 -24.266526966699804  80.957625119563829
   1.135912231405286 -24.264894316312123  81.046383006498658
   0.400511674029699 -24.276021148835568  81.126481736962901
   0.277035173019626 -24.277392701458147  81.098748843823444
  -0.510571683360327 -24.266700541188101  81.087069317970830
  -0.856734715903810 -24.252852374546308  81.088230323464373
  -1.388710505659353 -24.225305427315298  81.083250423518834
  -1.847825686590386 -24.194687018281151  81.066285325960706
  -2.392809534195841 -24.146164866998156  81.060467077118957
  -2.881367881544211 -24.090131612909357  81.066435222678095
  -3.352099546930662 -24.029669852284876  81.062345297043947
  -3.819183631562334 -23.960666020052120  81.056271793112359
  -4.261310413276053 -23.887243528047382  81.059347865313242
  -4.794071726647855 -23.785557176185868  81.067212555590373
  -5.163155456614966 -23.709360690194700  81.065863750888980
  -5.662692250859518 -23.596776324493863  81.058960285978642
  -6.061298369099768 -23.497686007705560  81.057783089721610
  -6.617012785266678 -23.348652613570380  81.060490397061898
  -7.002300546853200 -23.237060131385086  81.059236813813200
  -7.457000953624296 -23.098252276712849  81.051037629579298
  -7.964027193917168 -22.924858318804272  81.041598742417989
  -8.388643384469930 -22.774677044787616  81.057132466176057
  -9.057861506513690 -22.528590913378693  81.009433431950924
  -9.097754600745473 -22.515219291372947  80.989326235814076
  -9.343147394498404 -22.406295703643696  81.044509234979671
  -9.943971369020383 -22.145058021532542  81.093051804285338
 -10.061700648782697 -22.091162685750767  81.086114482122028
 -10.744586642505194 -21.769092743723441  81.084673388139237
 -10.998823908437455 -21.642457594289219  81.066794762629158
 -11.585584458405062 -21.335495614486533  81.054168613996140
 -11.881282743962311 -21.170319148876906  81.059357646967200
 -12.340715290766610 -20.906752191031337  81.070238944949352
 -12.727534805564417 -20.667551181806971  81.088123346192987
 -13.225961498924056 -20.356220139733431  81.078706420493603
 -13.639491739602672 -20.092590099284486  81.034022541684678
 -13.735319936027302 -20.028537268792022  81.011357842838763
 -14.310892835553961 -19.616681889489069  81.019936238405066
 -14.422084523823285 -19.534159624640250  81.036706643698381
 -15.011781826065825 -19.082722567846126  81.049775667996940
 -15.216154080470178 -18.918099039935516  81.051855890324731
 -15.652989691494341 -18.559608628983419  81.069612998943413
 -16.250542456486460 -18.044948136259968  81.022652234629362
 -16.326902733258269 -17.980629615266114  80.986434856501390
 -16.446241537574402 -17.866064625926150  81.035688517916000
 -16.878901334672385 -17.455274480291518  81.085634915708027
 -17.201533248203319 -17.137271106799012  81.062606186494818
 -17.487521896251952 -16.853215665245603  81.040776692874005
 -17.871356314850473 -16.445822993632085  81.108751127595340
 -18.006631399668311 -16.299023788109650  81.175588537619106
 -18.064223834635541 -16.235796399719057  81.131246847805741
 -18.542522029085703 -15.689643208017975  81.089570532525855
 -18.931166404228122 -15.221278466960793  81.060933293330962
 -19.003053095010820 -15.135118760404479  81.028789947295124
 -19.146914035992616 -14.943874616098274  81.087300889891580
 -19.486741239519478 -14.490316420455908  81.148115271177645
 -19.686225840639317 -14.216276248283267  81.105347494094133
 -19.903550138978680 -13.909281280569882  81.062907317865111
 -20.263299435544891 -13.369083925409239  81.105274946240613
 -20.384323229125737 -13.183877524444481  81.143805545220772
 -20.445619689145815 -13.090832336914211  81.107422205080226
 -20.809289777673886 -12.516438063316290  81.070112771571331
 -21.194279534549423 -11.884109659788868  81.017200822865874
 -21.231704919438691 -11.826497049533765  80.965845028305949
 -21.298396848267686 -11.697411751056245  81.022323571568506
 -21.556299937652923 -11.211227122265329  81.076958083460170
 -21.753666301084820 -10.807169349827870  81.043839596299819
 -21.925537539694417 -10.451423442036532  81.010424148629795
 -22.047232249465054 -10.185204228793376  81.053126534751740
 -22.251580757163143  -9.728053808907777  81.094214677581363
 -22.595642131908509  -8.937317733829458  81.038591202950414
 -22.593859900119739  -8.948878929148698  80.984356594558065
 -22.577418470536621  -8.984556444718786  81.023991787843727
 -22.849547945957905  -8.269621953863721  81.061185768438420
 -23.034162065438078  -7.742918831174521  81.085374514153642
 -23.111751207598065  -7.518235580659546  81.109162471623108
 -23.242603485896751  -7.105508215438009  81.048676680476760
 -23.320554188704143  -6.860129538368033  80.987517961744246
 -23.341437371859495  -6.774902454186125  81.027313331948960
 -23.515996992348747  -6.099363223780675  81.070436465777661
 -23.648717485675654  -5.559344658021221  81.100834564005822
 -23.693779680023123  -5.367049573802983  81.131322685991449
 -23.786268220018833  -4.961631014781160  81.071841312126452
 -23.859518829904431  -4.631320223866570  81.012742740736897
 -23.892380907926697  -4.439862701080228  81.053594900125475
 -23.969347963893867  -3.990707613118346  81.093032505852975
 -24.053698702947926  -3.419192962880493  81.044064059367685
 -24.078169946827032  -3.258277054205440  80.990249288040545
 -24.087698923257417  -3.151854888285404  81.042196737983346
 -24.141580579317061  -2.588730520251274  81.089136589673132
 -24.195998615976535  -1.871943451146878  81.126626839434721
 -24.203311593015705  -1.733450106170350  81.166184949138398
 -24.240787918096004  -1.034782966574237  81.100981458141064
 -24.257649654258088  -0.742213580897236  81.024441522963158
 -24.257088179341856  -0.746579795478685  81.032241144706887
 -24.261336466214093  -0.235136482466532  81.091898891261266
 -24.266936215316768   0.378139367553010  81.148767064175658
 -24.267434796890655   0.412618471596031  81.129581750398728
 -24.248063949402237   1.193169173287205  81.103952631582757
 -24.234871482735649   1.523475118122393  81.074157009421214
 -24.207274711900229   1.944407863014712  81.040461550010576
 -24.143867116330263   2.695646013123298  81.104143661113994
 -24.144719402984762   2.679539048978530  81.175531332334430
 -24.150559365031544   2.630505248205846  81.145748862157305
 -24.063092088272331   3.275940814591783  81.098483878648054
 -23.979075295720584   3.803189402912496  81.139478756901212
 -23.936257132785293   4.060691475582510  81.167883582774891
 -23.771457973287518   4.909775458950905  81.180219756596799
 -23.767585503875921   4.930760965186909  81.172736544057415
 -23.556057728766149   5.905344206085993  81.190567312976796
 -23.583751494562300   5.793101542212023  81.149989956186658
 -23.413776346962077   6.418574925868763  81.095576549738865
 -23.303031202916525   6.813692493409918  81.078780801178567
 -23.122174372558803   7.415256943520257  81.094931973384192
 -22.952022879153375   7.933978223125557  81.109459926285723
 -22.802543553862055   8.369548474519403  81.089905733742270
 -22.617861967073281   8.902546456378655  81.029069796979798
 -22.657520258172664   8.805255820221513  80.996035480895344
 -22.317888245145053   9.616342729920181  81.015655850908431
 -22.307797292880036   9.637771837135176  81.029166568235595
 -21.979751716702083  10.361126891203883  81.036576348882548
 -21.948055206272969  10.427041829682119  81.027229883278210
 -21.567495010301450  11.200055622135562  81.026922756520918
 -21.501361073141354  11.325541241939867  81.065525457831697
 -21.202762728790582  11.872553916765131  81.090289442279825
 -21.018983738390812  12.189150532042026  81.091959028498124
 -20.771859280812638  12.603125465174283  81.098497924895469
 -20.490898222685292  13.051112331253082  81.103448373933546
 -20.351164717510642  13.267061494057462  81.112617943477687
 -19.973550459307145  13.829701128390017  81.124417109996998
 -19.870437914570527  13.977693816877458  81.133382739045501
 -19.521600135054371  14.461112924904761  81.143655775151558
 -19.393489750247799  14.631750967171799  81.152220204179073
 -18.968589648727050  15.178934077631849  81.165078569738597
 -18.833124184598926  15.346894122609552  81.170237791866271
 -18.389867358023292  15.870899248531220  81.180044453024919
 -18.332689930419434  15.935612639586358  81.195648913253564
 -17.686855554613754  16.647524156938353  81.202397774747325
 -17.736877134309378  16.594040236859438  81.210087398026943
 -17.512907748151669  16.827426646716333  81.116791161332628
 -17.122166205916574  17.235866883763769  81.012395967503437
 -17.171887720459260  17.187813374791844  80.998633335480079
 -16.891004512260746  17.450540523023697  81.090970653012747
 -16.474725314127316  17.844615528018618  81.187862512164756
 -16.506019935380753  17.815424413589604  81.195323726108683
 -15.852990444435235  18.404269028265951  81.198616510154878
 -15.875283366037479  18.385301059950358  81.186566160744931
 -15.205702700150940  18.944262731328799  81.191299169263715
 -15.208355991295802  18.941760813843736  81.201492432322965
 -14.603659970461640  19.403289893756057  81.194920194260135
 -14.502647916146666  19.478116775294932  81.181948821978864
 -13.900953274830687  19.902831844664458  81.166251133490803
 -13.607559259651568  20.101774201983368  81.157790143685062
 -13.173396359195431  20.386237972083265  81.136546948396855
 -12.714199652159365  20.680109408819547  81.095902087720305
 -12.477893202314466  20.824076716690804  81.044292300803946
 -11.989913847336982  21.115520537124883  81.127826110636192
 -11.740944781743789  21.258853850410631  81.209971562467828
 -11.610991493870706  21.338857624765559  81.104549918493589
 -11.265768121926916  21.530032193729042  81.046999926165412
 -10.957874818304724  21.678650536950418  81.080170075746807
 -10.543217050159200  21.878064813395099  81.108328411464512
  -9.989947383501361  22.126300705155671  81.155750997086855
  -9.684958304187441  22.265968821890226  81.171403500477055
  -9.326899479319479  22.411062459093934  81.184218156056076
  -8.870383412124951  22.597755818654342  81.159193228270766
  -8.209372818459915  22.846403345285903  81.145640231634033
  -7.949315195204555  22.942138308365742  81.129785115110764
  -7.333237433323499  23.150566945359706  81.122455764927167
  -6.992694013019671  23.258756285089138  81.125108291468536
  -6.662464796513619  23.359124042269194  81.127351611863546
  -6.042646093319188  23.521125400103124  81.190505471521092
  -6.016730585037983  23.527633894461843  81.226881392172544
  -5.977979238288269  23.538175698316323  81.135360076230796
  -5.224434894555007  23.710627606022218  81.037701639768542
  -4.950097664008313  23.766068089740134  81.057812619521897
  -4.358887454658241  23.880930853358041  81.074021881975554
  -3.907628032177853  23.959186557780303  81.091120536178991
  -3.562339394698499  24.014854453365352  81.111903644391731
  -2.884169775341783  24.119989315198683  81.154136980242512
  -2.863889560285086  24.122531273384027  81.177605024617336
  -2.257312515488886  24.185968372417165  81.172700414120172
  -2.274491430550882  24.185216853606541  81.153719849140501
  -1.522971204788479  24.230377652946189  81.122350384705328
  -1.374776748206277  24.238799376497628  81.106534555783114
  -0.622452533553157  24.265100338553189  81.093656606466610
  -0.458105314069497  24.268853505876251  81.089492507703923
   0.306099114324222  24.273292390912371  81.096434393117860
   0.482785985669196  24.270407783500552  81.112721150731801
   1.168099133030736  24.253068257530575  81.123253527481282
   1.264823424249873  24.248554935424803  81.137827368357733
   2.103725377706637  24.205145672532801  81.168691330135374
   1.986292435435691  24.214174716644820  81.176776465306219
   2.423918162170111  24.167786579131047  81.110297053030536
   2.736743434509091  24.137556236270335  81.029403942567740
   2.653998367081707  24.150661636064122  80.986548378060689
   3.414798342964153  24.034890112545625  81.051915306188135
   3.712651270564430  23.988501383146406  81.121599869507577
   3.664712271768504  23.996206831937709  81.115075530268072
   3.638448109820892  24.002937759064253  81.039146591434729
   4.637353227838481  23.829687115888845  80.973024763079820
   4.876863045603935  23.783858223210022  81.015242660224715
   5.367006992913251  23.682965270238643  81.048335125771615
   5.949222435017547  23.548814811576957  81.071189529526762
   6.024572953152250  23.529750966351813  81.097295766676226
   6.170909446124413  23.494018023025724  81.026906448353259
   6.714852781584285  23.349468626398057  80.964523944317364
   7.315157726203318  23.164777798562199  81.026402735966784
   7.324082870674077  23.159875836984895  81.095414203995986
   7.337092357543103  23.154546832793095  81.108185298991430
   8.082794209353608  22.900219057302138  81.104660717665098
   8.562098157681252  22.720270238569650  81.102496977393514
   8.893152821239333  22.595413038886246  81.081802379321516
   9.465575623488387  22.363480739554369  81.075201068992158
   9.735775652305268  22.249733498147037  81.066753966695074
  10.229803279519317  22.026448645287665  81.059693559442678
  10.586494069467978  21.858832134494421  81.051321407310155
  11.087091565117284  21.610294658431879  81.046115071648600
  11.473938324274204  21.410951237238169  81.028026346778148
  11.846016223552029  21.203922749078700  81.000643589050654
  12.373878190054914  20.901405239512300  80.997761012415765
  12.710152639677318  20.700565790181994  81.010233808938764
  13.129246371175372  20.439431407418496  81.011607609735563
  13.428226101335069  20.242079527119309  81.005007560241964
  13.940003826634653  19.892306122717891  81.012679619983984
  14.237887048079569  19.680839051481506  81.031972713208219
  14.638196091419196  19.383690260272008  81.043856877429690
  14.894696466962008  19.184268405758338  81.053978875680286
  15.393659532692256  18.777374802948938  81.050990936714641
  15.629140890775794  18.576863073565214  81.002635030129184
  16.218461482523164  18.074616226577923  81.072500489178594
  16.202592293804738  18.087003366854283  81.134570823855782
  16.245887224892879  18.049710604250365  81.040057245400689
  16.788900624894900  17.543679176412390  80.943678121371192
  16.904448074205810  17.427200609356028  80.984285851165254
  17.365837581897715  16.950197941866545  81.032818426384324
  17.790710333295699  16.506586796324758  81.060065061722284
  17.986612692942227  16.295569996022369  81.065392730594098
  18.527693118269841  15.684741641769612  81.077158773805621
  18.541850070293556  15.667662026127052  81.086090405621945
  19.194351236719154  14.866719575326334  81.094233872232934
  19.196200556764026  14.862114824728522  81.157546255102133
  19.222870860361990  14.836250143842854  81.008520478142700
  19.528550460473731  14.468349186614928  80.856416974759867
  19.733472852420526  14.159332185577153  80.901368067357225
  19.869510234381067  13.960271857521114  80.980473284745173
  20.259653758719814  13.369974571668083  81.025561628182601
  20.446715813442736  13.082189694082970  81.011567451658536
  20.781387314540055  12.573354378628723  80.971770575008392
  20.834174772804520  12.482458149836692  80.992674968335820
  21.162313982315780  11.910642329107898  81.038705980373379
  21.508817701146928  11.285662377259831  81.088535208594664
  21.546893959474708  11.213823736600430  81.136586273100818
  21.596721056811802  11.116285405888066  81.078029660114453
  21.914691728117997  10.471868643153204  81.017073139287035
  22.204564921324092   9.840974637505299  81.060186411567003
  22.250867226159656   9.735102154723421  81.107467351666173
  22.324441214623818   9.560077629038963  81.073266397048954
  22.604692273190629   8.882920372975821  81.042369054896966
  22.817761561552906   8.334923030449843  81.083639932587730
  22.872256412997643   8.190645332984690  81.126574428819382
  22.945053157171404   7.982952008793618  81.077442758266926
  23.111214639055248   7.502333660002764  81.013214460098965
  23.160961244908563   7.329744530139139  81.006307145091668
  23.331762491073651   6.740125007037577  81.005823257287318
  23.529060297498113   6.000826108537673  81.049818125669859
  23.562959947303341   5.863158583621452  81.099096569071079
  23.626438444541272   5.592005873943192  81.045590119969233
  23.734577858216579   5.110026210372192  80.991751126488410
  23.794378827381475   4.809012887563795  81.022058828442766
  23.893813044424554   4.290915299067915  81.052144180446376
  23.993442980988227   3.746298666534145  80.992099948396685
  24.024320683059067   3.573646081443033  80.932633042189835
  24.046311774567815   3.410986500630899  80.989667503978509
  24.128031308225456   2.794899871500936  81.049400468666875
  24.209272171611634   2.030092955940126  81.091403184345722
  24.201204615875064   2.110728575053209  81.132147278550548
  24.196089529939989   2.190664684938715  81.087434727958538
  24.247518684443907   1.299046378531552  81.046024698773465
  24.268464887993566   0.778092333751535  81.002112570979904
  24.275570494673410   0.524529020626052  80.955794944911332
  24.278995360400639  -0.009939070172719  81.021329915660260
  24.277936097631699  -0.328801147562054  81.087391387800054
  24.276068429529410  -0.448447928746336  81.067888845006465
figure
plot3(vertex_segment(:,1), vertex_segment(:,2), vertex_segment(:,3))
grid
% view(0,90)
% axis('equal')
daspect([100 100 1])
xlabel('vertex\_segment(:,1)')
ylabel('vertex\_segment(:,2)')
zlabel('vertex\_segment(:,3)')
title('vertex\_segment')

[vectors(:,1), vectors(:,2), vectors(:,3)] = sph2cart(angle_phi_theta(:,1), angle_phi_theta(:,2), 1);
figure
plot3(vectors(:,1), vectors(:,2), vectors(:,3))
grid
xlabel('vectors(:,1)')
ylabel('vectors(:,2)')
zlabel('vectors(:,3)')
title('vectors')

% view(0,90)
% axis('equal')
% daspect([100 100 1])
figure
quiver3(vertex_segment(:,1),vertex_segment(:,2),vertex_segment(:,3),...
        vectors(:,1),vectors(:,2),vectors(:,3),0.8,'Color','green','LineWidth',1);hold on;
daspect([10 10 1])

a = linspace(0, 2*pi, size(vectors,1)).';
vectors = [cos(a) sin(a) 2*ones(size(a))];
% vectors = [cos(a) sin(a) cos(a)];
figure
quiver3(vertex_segment(:,1),vertex_segment(:,2),vertex_segment(:,3),...
        vectors(:,1),vectors(:,2),vectors(:,3),0.8,'Color','green','LineWidth',1);hold on;
daspect([10 10 1])

% view(0,90)
.
  bird
 on 17 Apr 2025
				Thank you very much for your answer. I have found the reason for the question, because I was busy with other things and did not reply in time. The main reason is that in the calculation of sph2cart, the Angle azimuth corresponding to the vector is sorted in counter-clockwise order, so the corresponding vertex_segment should also be sorted in counter-clockwise order. If clockwise ordering occurs, problems like mine will occur. Therefore, the vertex_segment need to be sorted in reverse order before calculation:
clear all
clc
close all
load angles.mat
load vertices.mat
vertex_segment=flipud(vertex_segment); % important
[vectors(:,1), vectors(:,2), vectors(:,3)] = sph2cart(angle_phi_theta(:,1), angle_phi_theta(:,2), 1);
quiver3(vertex_segment(:,1),vertex_segment(:,2),vertex_segment(:,3),...
    vectors(:,1),vectors(:,2),vectors(:,3),0.8,'Color','green','LineWidth',1);hold on;
  Star Strider
      
      
 on 17 Apr 2025
				As always, my pleasure!  
Thank you for clarifying that.  
The counter-clockwise direction is the default mathematically, and MATLAB follows that convention.  That ‘vertex_segment’ was oriented in the opposite direction is also the reason I could not get my simulations to work, since all my ‘vectors’ matrices were also counter-clockwise.  
.
More Answers (1)
  Mathieu NOE
      
 on 15 Apr 2025
        hello 
I could not find any quiver issue (tried to reproduce it my way) , but at the end I suspected maybe you need to invert the data order (between azimut and elevation) when you use sph2cart (we don't know how your data angle_phi_theta is generated )
clear all
clc
close all
load angles.mat
load vertices.mat
% [vectors(:,1), vectors(:,2), vectors(:,3)] = sph2cart(angle_phi_theta(:,1), angle_phi_theta(:,2), 1);
[vectors(:,1), vectors(:,2), vectors(:,3)] = sph2cart(angle_phi_theta(:,2), angle_phi_theta(:,1), 1);
% TMW quiver 
figure
quiver(vertex_segment(:,1),vertex_segment(:,2),...
        vectors(:,1),vectors(:,2),0.8,'Color','green','LineWidth',1);hold on;

% alternative quiver 
figure
plot(vertex_segment(:,1),vertex_segment(:,2));
hold on;
scal_factor = 3;
for k = 1:numel(vectors(:,1))
    dx = vertex_segment(k,1)+ scal_factor*[0 vectors(k,1)];
    dy = vertex_segment(k,2)+ scal_factor*[0 vectors(k,2)];
    plot(dx,dy,'r');
end

% final plot 
figure
quiver3(vertex_segment(:,1),vertex_segment(:,2),vertex_segment(:,3),...
        vectors(:,1),vectors(:,2),vectors(:,3),0.8,'Color','green','LineWidth',1);hold on;
    quiver3(vectors(:,1),vectors(:,2),vectors(:,3),...
        vertex_segment(:,1),vertex_segment(:,2),vertex_segment(:,3),0.8,'Color','green','LineWidth',1);hold on;

See Also
Categories
				Find more on Startup and Shutdown in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)




