我的点都是球面的一部分。如何创建3D球体,其中球体的颜色取决于点的密度(平滑的)。下图提供了数据点的示例。
使用以下代码,可以为这些点着色:
x = data(:,1);
y = data(:,2);
z = data(:,3);
D = [x(:), y(:), z(:)];
N = numel(x);
%// calculation of color vector
[n,m] = ndgrid(1:N,1:N);
%// euclidian distance of each point to every other point
X = arrayfun(@(a,b) sum( (D(a,:) - D(b,:)).^2 ), n, m);
%// threshold factor
T = 1;
%// sort distances of points
Y = sort(X,2);
%// calculate average distance of the closest T% of all points
Z = mean(Y(:,2:ceil(N*T)),2);
%// plot
colormap jet;
scatter3(x,y,z,20,-Z,'filled');
title('T = 0.01')
[x,y,z] = sphere;
surf(x,y,z,rand(length(x)));
colormap jet
shading interp
我的数据示例:
-0.636016480755703 0.617525876796302 -0.0928047432418846
-0.973951523685005 1.33968621140501 -0.484260283616615
-1.09449677739217 1.95314823996034 -0.997620228061477
-1.27650273224044 2.30054644808743 -1.52076502732240
-1.34107124912069 2.50643151442066 -1.93523263993568
-1.41743718592965 2.64326633165829 -2.38693467336683
-1.52722674072605 2.66172386431264 -2.68924816504662
-1.78737177571955 2.53918932377253 -2.86176675629917
-2.13798636181308 2.25411151223426 -2.71760930605696
-2.63246062794664 1.72971210753335 -2.72474671481593
-3.03187531422826 1.12946204122675 -3.07732528909000
-3.24477552244776 0.394710528947106 -3.67518248175182
2.78947368421053 1.11300309597523 -4.46904024767802
2.49650108417110 1.17716341415336 -4.93987778434851
2.52268839923534 0.940134822416742 -5.07883086829661
2.87130058385343 0.507398832293135 -4.76887457217636
3.04415584415584 0.461038961038961 -4.41298701298701
3.09087249672940 0.653567475093087 -4.11894938110094
3.11987397479496 0.702540508101620 -3.94573914782957
3.17966101694915 0.719840478564307 -3.52233300099701
3.12836149155253 0.840997700689793 -2.86519044286714
2.97330943133154 0.892490787770142 -2.26048202370282
2.81690697215090 0.873000197511357 -1.86114951609718
2.72014039944631 0.816195372750643 -1.64094324698438
2.50647023691021 0.872387019709337 -1.35715707744376
2.23888664376642 0.836886239644373 -1.02939987876339
1.96850235730765 0.814575183067509 -0.776808105125891
1.64841095342794 1.11333200079952 -0.690885468718768
1.36944528036914 1.18331828668874 -0.567609589728157
0.920234429323533 0.813251216847125 -0.225489222211184
0.570574643359454 0.388738195700221 -0.0264215390797675
0.316863696069516 -0.0561281196322118 0.0646660604223506
0.338646811912852 -0.391515090945433 0.0651609034579250
0.479434319290907 -0.676526242406135 0.0231052683995618
0.505991285403050 -0.746187363834423 0.00925925925925952
0.399658325796402 -0.813636820420058 0.0130640136669684
0.182226660009985 -0.957613579630554 0.00439340988517190
-0.0248032672576950 -1.24863034166750 -0.0676860245044320
-0.283441074092491 -1.72710094480358 -0.272948781700647
-0.527511004401761 -2.34133653461385 -0.705782312925170
-0.797852242219350 -2.97176096251367 -1.49487918862484
-0.922330097087379 -3.29166249624662 -2.23876488839956
-0.898067487734055 -3.46104936417343 -3.16261139481326
-0.727430211839240 -3.46159176400713 -3.78058800237577
-0.614893829129698 -3.34522978765826 -4.33002691655867
-0.453940686573228 -3.06104001625025 -4.98694901482836
-0.173647905628312 -2.72118364490653 -5.48340497850645
0.0242345666699911 -2.38655629799541 -5.81115986835544
0.198836859520706 -2.10383034192319 -6.01564223403189
0.380042037834051 -1.79871884696227 -6.17951156040436
0.423617429986857 -1.63856030735012 -6.25290668284299
0.368721000605205 -1.66920516441396 -6.24581400040347
0.0171154038634771 -1.99409468521670 -6.09303373035732
-0.396368687369779 -2.45550153785098 -5.72055759499951
-0.911024174942322 -3.02593038419099 -4.85911325107834
-1.22442557442557 -3.29275724275724 -3.85614385614386
-1.22364472894579 -3.30446089217844 -2.70414082816563
-1.09318766066838 -3.01586909234724 -1.74006327862369
-0.846371252649642 -2.61244574543252 -1.05284142525487
-0.594202898550724 -2.24637681159420 -0.644927536231885
-0.493466023321271 -2.07438681141938 -0.501708886208283
-0.414079822616408 -1.88802660753880 -0.374168514412417
-0.0486402719456110 -1.25204959008198 -0.0690361927614474
0.514052222443692 -0.238489136934423 0.0455451465018948
1.25832163625426 0.215410066172047 -0.196310407058352
1.72030784508441 0.633813306852036 -0.532571996027806
2.33757173956066 1.28933306946368 -1.43583019988126
2.66762105686156 1.66294956801286 -2.65888085191883
2.82720953326713 1.42879841112215 -3.80993048659384
2.70761349939735 1.02732020891924 -4.72047006830052
2.42173094081491 0.500297412511153 -5.41731932189947
1.64370927318296 -0.734636591478697 -6.11152882205514
1.19525675811476 -1.17174153351422 -6.22434931162697
1.11648548917922 -1.26179315847213 -6.22569063528473
1.11648548917922 -1.26179315847213 -6.22569063528473
1.29463307776561 -1.04600219058050 -6.21905805038335
1.69427680547174 -0.494216455441561 -6.11265338966003
2.19971642697995 0.369252582540004 -5.67956248734049
2.63406087304766 1.03103724469363 -4.84551461754105
2.90801393728223 1.36689895470383 -3.48257839721254
2.69187842551071 1.30109616342800 -2.03637269556552
2.04063692987744 0.843078159533856 -0.848754269640346
1.28362077559565 0.0458578406938491 -0.185724254810089
0.722807017543860 -0.518245614035088 -0.00491228070175431
0.548188515490968 -0.832172772227268 -0.0118579069532743
0.489908530522967 -1.08401272618811 -0.0579140982302633
0.485282298573438 -1.30887080570625 -0.124573035965441
0.674118231495281 -1.33253849975161 -0.168007948335817
0.910319782104308 -1.33229093110057 -0.229244426510643
1.52194752774975 -1.40302724520686 -0.515186680121089
1.94507084414289 -1.55647575334265 -0.876222310915985
2.35918818446699 -1.89234401687933 -1.55827388727017
2.71365858525392 -2.06993913997805 -2.58001596328445
2.86434225027552 -1.95721871555956 -3.17287846909127
2.85724240915879 -1.92110502737680 -3.66057740169238
2.87056949422541 -1.78156113102350 -3.98426921545201
2.87284396309667 -1.61111111111111 -4.25952667468913
2.80383257690368 -1.63519919314170 -4.40963187090267
2.74593029062219 -1.74528113452512 -4.41146509537601
2.79961927662559 -1.78649433924456 -4.21245366195772
2.90093495126318 -1.80893176845037 -3.77849612094689
2.92225456735595 -1.85735796024895 -3.29276249749046
2.79813695871098 -1.99234642497482 -2.74043303121853
2.69918862065511 -1.87313432835821 -2.15235901031754
2.52209558088382 -1.58498300339932 -1.52319536092781
2.00474364150182 -1.47204279370206 -0.880904319741623
1.51878192927978 -1.62576379845738 -0.618351197034960
1.23150095123661 -1.63627716030840 -0.477520777010114
0.531772406847935 -1.78439073514602 -0.336606243705942
0.0184244597151679 -1.70859476147794 -0.250473060452145
-0.761328398519556 -1.39836951085326 -0.212463739121736
-1.14685385314615 -1.00161599838400 -0.209473790526209
-1.46421063169486 -0.401441585744319 -0.256982680949045
-1.65316831683168 0.183663366336634 -0.385742574257425
-1.74656382873529 0.675961633540987 -0.563532087412242
-1.89565826330532 0.973389355742297 -0.793417366946779
-2.13232939763858 1.09455673404042 -1.06588953372023
-2.22335431025872 1.24398162021776 -1.26261112775946
-2.25349301397206 1.26686626746507 -1.31457085828343
-2.32195949316572 1.27616482091190 -1.40491868701985
-2.32195949316572 1.27616482091190 -1.40491868701985
-2.25349301397206 1.26686626746507 -1.31457085828343
-1.94300518134715 1.07393383818254 -0.884216819449980
-1.58513309894525 0.672978402812657 -0.464239075841286
-1.23895482198065 0.186895382467338 -0.184202652837339
-0.579979879275654 -0.312776659959758 0.0340040241448691
0.0370258577321662 -0.908441493107959 0.0195693731763762
0.0376980148385803 -1.41537998796872 -0.125025065169440
-0.218357293656379 -1.75379511410476 -0.280838443751885
-0.596396934408281 -2.03976311336717 -0.499353040708669
-0.921337706221428 -2.33015305108328 -0.810922281852514
-1.15569341604963 -2.61947168300981 -1.20672403442065
-1.34566968781470 -2.98257804632427 -1.89088620342397
-1.47722515698196 -3.13345958337486 -2.45724110435563
-1.56538309245694 -3.18704216986735 -3.03009305088101
-1.66732830488289 -3.12643906312029 -3.51667328304883
-1.69259886442873 -3.09971112660624 -3.62316963841020
-1.71797696544817 -3.10520781171758 -3.39609414121182
-1.73907022749753 -3.08506429277943 -2.99891196834817
-1.55176565008026 -3.07383627608347 -2.38804173354735
-1.29407651583258 -2.96668664469084 -1.81125761662172
-1.06947201270345 -2.71119491861850 -1.26915442635967
-0.663021769522668 -2.13655881765528 -0.580487317755142
-0.209927507047926 -1.41683447442610 -0.132400322190898
0.163531402408679 -0.794366477555489 0.0366278491091858
0.418277331747448 -0.462037863019130 0.0522846664684309
0.586739327883742 -0.290644868301544 0.0331516802906444
0.652918908149034 -0.108686989440127 0.0178322374975086
0.687443901466042 0.142016555300688 -0.00982347661314398
0.774385999801134 0.549766331908124 -0.105846673958437
0.841714797849034 0.982473610834495 -0.267128062139017
0.827499243417734 1.33965499848684 -0.436951477857360
0.812180194642320 1.71977525835256 -0.683806561653456
0.701562344511892 1.92168374962683 -0.817593790426909
0.435846429281878 2.00925004973145 -0.835289437039984
0.0682452642073778 2.07342971086740 -0.857926221335992
-0.307490144546649 2.10891539472354 -0.912059031638532
-0.719540461553966 2.05698881386677 -0.951073264133830
-1.10075818036712 2.00598563447726 -1.05367118914605
-1.56707560343108 1.90325154598045 -1.24182126471175
-1.69690374913443 1.87555643486003 -1.31931941834009
-1.91472868217054 1.74031007751938 -1.37984496124031
-2.14285714285714 1.58571428571429 -1.47142857142857
-2.36444466520962 1.38793959864892 -1.56134512219352
-2.58613043040016 0.984326176796694 -1.54314081241810
-2.78857029467209 0.479015775374541 -1.57148526639548
-2.87015945330296 -0.105922551252847 -1.55694760820046
-2.83612343686971 -1.03781766841468 -1.68132311415894
-2.71839481555334 -1.49127617148554 -1.76859421734796
-2.48778316351766 -1.82011079236324 -1.67815807696112
-2.17667773417849 -2.01398531039340 -1.44018512928866
-1.81555333998006 -2.16919242273180 -1.21395812562313
-1.31528822055138 -2.21709273182957 -0.899348370927319
-0.798962386511025 -2.21465629053178 -0.675745784695200
-0.261611611611612 -2.25895895895896 -0.600350350350350
0.208694338101954 -2.17585129961717 -0.534757203304453
0.449437082793664 -1.88831324100827 -0.379645312344326
1.00702458605118 -1.46929252383342 -0.313296537882589
1.28716658278812 -1.08983392048314 -0.289783593356819
1.57556687643592 -0.714613924682849 -0.347118170012986
1.68775020016013 -0.484787830264211 -0.382706164931946
1.61437908496732 -0.599346405228758 -0.352287581699347
1.57417582417582 -0.575274725274726 -0.327472527472528
1.78015328761597 -0.188987494957644 -0.430012101653893
2.06253743262128 0.340786584148532 -0.696196845677780
2.25189017111023 0.728014325507362 -0.992240350179069
2.30490383647165 0.963548484543349 -1.16680092639211
2.16848971399900 1.16432513798294 -1.14706472654290
1.52051204515674 1.44758592883782 -0.814585223263785
0.938315894369706 1.52640757349278 -0.587493771798705
0.270871327254306 1.42152988855117 -0.376393110435664
-0.431318681318681 1.27967032967033 -0.317582417582417
-1.24290141971606 1.11672665466907 -0.472905418916217
-1.67691236446832 0.878344772704665 -0.596737292350543
-2.09241823587711 0.562239841427156 -0.782804757185331
-2.46963156309608 0.160676638891678 -1.04607971087240
-2.80539575481055 -0.297758381273557 -1.44653838524102
-3.04411764705882 -0.720588235294118 -1.97058823529412
-3.10657776893223 -0.932530600059707 -2.24584535774704
-3.10657776893223 -0.932530600059707 -2.24584535774704
-3.09186140209508 -0.923851732473811 -2.19580983078163
-3.06973971786211 -0.972282932644546 -2.16371945161931
-2.97409275190349 -1.18797587263918 -2.06679521408089
-2.58697813121272 -1.65029821073559 -1.67783300198807
-2.17490305260018 -1.82484836432336 -1.27145271949886
-1.54121682978509 -1.85420240137221 -0.764806780345071
-0.516422082459818 -1.59888190076869 -0.243535988819008
0.621063189568706 -1.10441323971916 -0.0862587763289868
1.66834120365719 -0.593388927961419 -0.382296794936200
2.25558547775783 -0.621284659884301 -0.821115100738080
2.66296629662966 -0.781178117811781 -1.31313131313131
2.87842586085734 -1.01686577652846 -1.74947294448349
2.96028014007004 -1.22826413206603 -2.06478239119560
2.91112000800721 -1.21779601641477 -1.94089680712641
2.57236973447794 -0.810141744859253 -1.20203633459772
1.39727199516811 -0.142490436883430 -0.223273605798269
-0.231495280675608 -0.227620466964729 0.0772975658221564
-1.18559766176174 -0.862426930054425 -0.193156621648861
-1.58402645555667 -1.20913919230384 -0.475849283495340
-1.75749674054759 -1.35924180122355 -0.641209507571959
-1.79383084577114 -1.39004975124378 -0.679502487562189
-1.71299871299871 -1.39956439956440 -0.629096129096129
-1.11655827913957 -1.16223111555778 -0.242321160580290
-0.445971516781197 -0.933323374165920 -0.0159346678617660
0.420428269830099 -0.767165979692369 0.0181461747260472
1.62276740919125 -0.599237407184427 -0.356963676500100
2.24262721183645 -0.868489453164051 -0.859792062381285
2.62592815572948 -1.10194661850291 -1.37818583182822
2.92154718106791 -1.41344337277518 -2.13826190712936
3.03345724907063 -1.55018587360595 -2.76765799256506
3.09189297524802 -1.50085178875639 -3.27382503256839
3.09373122371320 -1.44131784498298 -3.61686360905267
3.12990756386045 -1.36810456217076 -3.53021568432561
3.24122807017544 -1.02192982456140 -3.09649122807018
3.16491701659668 -0.546140771845631 -2.23975204959008
2.47121620273371 -0.127007881871695 -1.01326948019555
1.11460425873845 -0.123443149859381 -0.108879067898755
-0.332014246141670 -0.423624851602691 0.0643055005935889
-1.35305494941480 -1.01175362031343 -0.298055941281492
-1.85162601626016 -1.81846123339282 -0.961679555819949
-2.02630258006224 -1.98925810661580 -1.25148077502259
-2.06198595787362 -1.93941825476429 -1.24523570712136
-2.02630258006224 -1.98925810661580 -1.25148077502259
-1.88748763600396 -1.92814045499505 -1.07141444114738
-0.928151469855506 -1.61086198305929 -0.349725959142999
-0.0390547263681593 -0.873084577114428 0.0264676616915427
0.855323383084577 -0.356019900497513 -0.0278606965174126
1.91169066559259 -0.262007854193938 -0.516816030611217
2.74024280124411 -0.390037122504264 -1.35356677034213
3.18088116410671 -0.598625707356508 -2.30901374292644
3.27699018538713 -0.869138495092693 -3.19520174482007
3.20708582834331 -1.02165668662675 -3.74411177644711
3.14159113796576 -1.02769385699899 -4.05659617321249
3.13289695527125 -1.02211643360111 -4.09486264008728
3.23694438907714 -0.827287223440303 -3.81029499701017
3.32393239323932 -0.460796079607961 -3.07100710071007
2.90476664344711 -0.0317444521842970 -1.62528609811922
1.52950526524935 -0.148023047883966 -0.287701172263063
0.185110663983903 -0.638430583501006 0.0575452716297797
-1.09335745151241 -1.15500954677922 -0.231635011556627
-1.58385217915244 -1.54348262703354 -0.614982928298855
-1.71489128266507 -1.62602234191103 -0.741871135048873
-1.71489128266507 -1.62602234191103 -0.741871135048873
-1.65856458374925 -1.63770213615492 -0.710620882411659
-1.41790441547944 -1.54981307466909 -0.525108618773366
-1.29696668324217 -1.44157135753357 -0.417503729487817
-1.12397315167301 -1.18648567421358 -0.252554598276898
-0.854046242774566 -1.05780346820809 -0.128612716763007
-0.666666666666667 -1.33333333333333 -0.166666666666667
-0.521618405394685 -1.73125743752479 -0.307417691392304
-0.0915189746670674 -2.03509562431161 -0.433964153399419
1.20271210013908 -1.81606397774687 -0.561891515994436
1.86270346779901 -1.85527246992215 -0.996461429582448
1.86263846928499 -1.97301107754280 -1.08509566968782
1.76366703045937 -2.14922115289215 -1.15061017958131
1.76361819090455 -2.18985507246377 -1.18805597201399
1.68721529015647 -2.17250940780353 -1.10937809467221
1.65447768711595 -2.04371914979349 -0.976176085423593
1.60033760301857 -1.90715916989375 -0.838000198590011
1.44555845197514 -1.94866653298576 -0.770102265891318
1.31015187849720 -2.06075139888090 -0.774180655475619
1.16209202515221 -2.18400039924144 -0.793542269687593
1.04569463823002 -2.24302371935420 -0.788419374127964
0.958153103309526 -2.11618549441706 -0.656875565838447
0.961211161686127 -2.03423708687908 -0.600930140510587
1.00920920920921 -1.94034034034034 -0.557557557557558
1.01808382027000 -1.80727382631473 -0.481714688696353
0.951635560907084 -1.49859522376079 -0.307144290587999
0.803406952560166 -1.35560067346737 -0.207437852827573
0.785593473286240 -1.22505223360860 -0.158541438662819
0.580485838121157 -1.15290797298659 -0.0920270134059069
0.264785894206549 -1.10916876574307 -0.0380352644836268
-0.0502447307961242 -1.05444011587254 -0.0134352212566178
-0.339005104594135 -0.957711940746672 -0.00820738664798304
-0.516057585825028 -0.699889258028793 0.0143964562569212
-0.282254028625763 -0.610899809828846 0.0537984185767195
-0.313627353815659 -0.525173439048563 0.0592170465807742
-0.180463242698892 -0.550251762336354 0.0669687814702917
-0.0783649052841476 -0.817248255234297 0.0358923230309078
-0.0305602716468592 -0.871467092779387 0.0268650754019779
-0.0276997189883579 -0.866118024889603 0.0279004415897233
0.362864321608040 -0.759547738693467 0.0262311557788948
0.767242249823286 -0.540644249217409 -0.0170655356962532
0.732645497345487 -0.599569267755184 -0.0148752879895824
0.702180028129395 -0.490857946554149 0.00175808720112514
0.751281793505580 -0.310244294762240 -0.000854529003719851
0.798241206030151 -0.355075376884422 -0.0132160804020103
0.747126436781609 -0.454022988505747 -0.00574712643678188
0.489324726911619 -0.520953326713009 0.0381827209533263
0.258796481407437 -0.628248700519792 0.0537784886045589
0.217539977873881 -0.714723926380368 0.0457105501357740
0.0984422110552764 -0.856180904522613 0.0283919597989950
-0.154428614127727 -0.990734283152336 -0.00154428614127733
-0.298350228582787 -1.19866825680779 -0.0662890081494729
-0.546631864270656 -1.23100090352374 -0.109326372854132
-0.911847389558233 -1.03815261044177 -0.139959839357430
-1.06025781952633 -0.891775756970121 -0.153392625162387
-0.956119162640902 -0.889291465378422 -0.119162640901771
-0.957903780068729 -0.776632302405498 -0.0987972508591066
-0.983094928478544 -0.673201960588177 -0.0909772931879562
-0.917893375770838 -0.729809031231351 -0.0794708573702003
-0.916733911640105 -0.691194270728263 -0.0735323784547108
-0.849363437437836 -0.799035209866720 -0.0716132882434848
-0.744629833150165 -0.799330602457788 -0.0455090418623234
-0.598454636091725 -0.811714855433699 -0.0171485543369885
-0.481754002187531 -0.860495177488317 -0.00651287660336042