Distance between spheres with GJKΒΆ

plot spheres
2.065707349299925
0.0
0.5280306783837614
0.0
0.13979418785567055
0.7313904397305825
1.6809381731139519
0.2623716327826637
1.5208357085782809
0.49127152618040804
0.3209261488087267
0.6536413029917518
0.0
0.7114752706133556
0.6161940379307597
0.12881622520477584
0.20493386496421379
1.3008037073309275
0.0
0.3235426243596007
1.0572382209607865
0.7193311800395743
0.873362974435853
1.130884326881744
0.3631265912558383
0.5887167976540064
0.0
0.8612727714343154
1.576712148205994
1.343553402205369
2.195868634768677
0.0
0.48696213139951794
0.3898101080056878
0.8009603114038701
0.09146418257039707
0.0
1.4131058870485727
1.198029641515554
0.8374618989615795
0.5226039070334614
0.0753760571207117
0.46210430840568345
0.0
0.15747875037222084
0.0
0.08605108106629547
0.7540669399061884
1.4924391954089429
1.2838710476769095
1.1236664810731938
0.5376194779012711
0.0
0.7150721562009251
0.0
1.1363019094016185
0.7140688492950565
0.0
2.8962731597817135
0.46110027927847086
0.0
0.0
0.0
0.5003499164374032
0.264182074136659
0.0
1.1792419078563383
0.44450905614071096
0.6130415533420136
1.3377758580719519
0.09756769249452114
1.3842711210299894
0.0
0.6562877527747014
0.0
0.7012872588177668
0.5492910976946555
0.731704280038082
0.0
0.41294570325417496
0.13138231541270687
0.0
0.0
0.0
0.23891495143879685
0.0
0.0
0.7296761227614827
0.0
0.14198856349715155
1.2896855966213383
1.0989712315222826
1.202230652454926
0.19069649634053032
0.0
0.4009695021950556
0.019040124078947465
0.18064576513671388
0.5240535611222581
0.0
0.4349779598481595
0.0
0.0
1.8829231756652713
1.267281660495013
0.6361579437652679
0.0
0.3594805001887424
1.18138248970722
0.7400021017397714
0.0
1.0036211864471567
0.9072133927870648
1.075626669688077
0.0
1.6320939200757365
1.5516002147000993
0.44812316066788055
0.0
0.0
0.15608976118327256
0.0
2.3943703982779327
0.5414689215066111
0.6048861718582724
2.8438118925368188
1.411394784951918
1.0522423362231337
0.0
0.710218787258745
2.375029885602641
0.40506362657360245
0.0
1.7822592768854972
0.0
0.0
0.798181995082439
0.9032137166114437
1.0474506704950868
0.0
1.5972873673571428
0.6074627519217326
0.08422937905609501
1.6045474801866058
0.0
0.0
0.664162943613708
2.0838199993941995
0.5303630858290876
1.8050037406410615
1.0503046228798907
1.3901750563169117
0.977453606587232
0.0
0.09083085303415339
1.404606328862189
1.0279329471095209
0.0
0.3573406913356053
1.202293799847029
0.0
0.6350906439888547
0.617032004424716
0.0
0.9774230227497922
0.06614400194542067
2.0121182458144387
0.3192341933810508
0.05447187206519072
0.7308629504023062
0.22636360995407084
0.9761953295783847
1.321155789147141
0.0
0.03613499631781905
0.4482820694584952
0.0
1.3453968967096732
1.5124003015247531
1.2323979314010107
0.5758285307914309
2.678534736849973
1.2793973018186078
1.3597153385155303
0.027923902688881518
1.1096568120925006
1.3291272472960438
0.37289144720048933
0.0
0.30910693645119003
0.5370124471528659
0.0
0.4862349610693779
0.0
1.5836261200560753
0.1590517000409008
1.730892882681033
0.6530106189069241
0.3514653991333908
1.1551815482869534
0.9451871702355266
0.023940749705256916
1.5882106203801138
0.17330639524238345
0.0
0.0
2.219323824043924
0.35155587936157356
0.5824619916990997
0.24185201160873024
0.2601912202346848
0.15374545793380553
1.4324743773222024
1.1399237599073118
0.7926344230066048
0.29999461015513634
0.0
0.21294671511774899
0.6448311641097096
1.0113761016251588
0.14775832280750564
0.5204113597261728
0.0
0.03414976198333053
0.07047942650322336
2.01191111603733
0.9208789733031523
0.6938234142319133
0.49231579055807023
0.0
1.069330445881631
0.0
0.26160662618600905
0.657866326104903
0.6333333937962912
0.019140899265414815
1.1263063841297216
1.7269166755692846
1.029120484521705
1.0644199452149181
0.31497658923419186
0.5229258609644818
1.2914882990019951
0.0
0.0
0.0
1.1358718208742598
0.0
1.499219281927301
0.30224768133721236
0.0
0.4144727787051406
0.49944713131992785
0.0
0.6615498042356968
0.0
0.6752489279920433
0.24328517008881395
0.7589369569254595
0.002025860357929674
0.11634588785982883
0.3261740877651618
0.4389434682791769
0.3026591745321453
0.0
0.0
0.49511418079639985
1.0125988183244607
0.45855867518077764
0.6377533430858778
1.2379724132703382
0.7883296958481386
1.452823488025069
0.36916946320412275
0.874739030932987
1.750784894911395
0.26498729702839646
0.0
0.5608718254727083
2.239367831659204
0.0
0.7180289629885923
1.353987481042474
0.0
1.1408360218538698
0.056303769024402046
0.13412965429987997
0.0
0.8847755631097064
0.0
1.2539117359362169
0.0
0.4119065736529775
0.03929091380945035
0.0
2.196466863907047
0.840865570606084
0.725434709629932
1.5605917090105244
1.6925376942816517
0.0
0.7825447920223018
1.7293430353029262
0.0
0.0011231621907130587
0.0
0.5883540161499224
0.4770358051645164
0.04597869544945672
0.0
0.9516919633903236
0.0
0.0
1.032925090270386
0.21036884636256956
0.6171384650842922
0.0
0.8244625834202483
0.48804838676504453
0.3464947544826377
1.2610286295947133
0.0
0.24847502216622377
0.5303469195483926
0.0
0.28533601997314795
0.0070845370565019135
0.06321714371008114
2.04568725305992
1.7479219510271196
0.1263563784274779
0.0
1.5091620360301696
2.5588269598191244
0.06762265853727846
1.0753318694186422
1.3629868410261485
1.6581348030498655
0.4648256012165676
0.9153217465018799
1.2601093810795847
0.9165459849438579
0.0
0.0
0.5655815459861321
1.3564085933428607
0.0
0.0
0.2565891916265292
0.0
0.0
0.006347911565962034
0.43621092122875593
0.33105273123063395
0.0
1.2694582950660402
0.4152638215811433
0.0
0.3769398609742981
0.325978712086003
3.0199936792283246
0.7165364000549711
0.13963600746638416
1.2146595883078253
0.10197113862374706
0.0
1.0313364973711148
0.3191448145483093
0.0
0.24005088684787954
0.4580290528079701
0.0
1.6710048405190914
1.2680527939682074
1.409248109176414
0.23304373874011722
0.359435619447333
0.589437696376014
1.6075727555065118
2.371017543568354
0.8492644751106571
0.1273784877026334
1.8071186864138533
0.5831962289122944
0.7376427640609845
0.0
0.03543127996769963
3.1474211538161354
0.0
0.289738145295931
1.5726965104447561
0.0
0.671425111487336
0.0
0.7518200460909782
0.0
0.5491773679473709
1.3517812769149185
0.0971282148365062
0.7310928946912653
0.0
0.0
0.0
0.06308960674798474
1.3045480044303996
0.0
1.1506785160064659
1.032926333419074
2.543673918266564
1.0974049261375367
1.3496494181491454
0.06700418172740019
0.42886597923930264
0.4517011128667893
1.837089830244555
0.0
1.090892390953867
1.1459578730453712
0.0
0.41436973326075954
1.4901072147442211
0.9608556499765383
0.6859712238749734
0.6017285993410892
1.0278933918364768
0.6488435803316296
0.5005381242210217
0.5706125191941476
0.501846442064862
0.1350120840353802
0.9693320924669063
1.7663678009291763
1.4060872955087758
0.34597943575140133
0.2988896917698481
1.2666234001975851
0.0
0.0
1.1437003718120748
0.9667627130586313
0.13262745821462646
1.1381777964528867
1.2026752696914675
1.1984212122020421
1.2037877087196533
0.608468575905694
0.0
0.4830361159968286
0.0
0.7207481045221308
0.4370887980891759
2.4571884603751815
0.5982218034028675
0.5541912415534548
0.29143104045302326
0.7780256249424997
0.0
0.9356521363283808
0.0
1.7389236357153928
0.34169336692355023
0.0
1.5335173365571977
0.6032106406245352
0.874296284795872
2.134732554837157
1.389952855265905
0.5610779381702905
0.3127795301780302
0.200726204395475
0.18836715357096298
0.0
0.5057930381288274
0.25098888318839063
0.33092149563415735
1.5521631802624176
0.0
0.9563469037846418
0.21971018319016325
0.0
0.3714637124902849
1.441692948479733
0.18140649466648104
0.7449491743655087
1.8035760135939982
0.8941893179809909
0.0
0.0
0.0
0.0
0.652621101159587
0.7763470004008466
0.6578810429981063
0.0
0.014166620021199514
0.016678011558903957
0.0
0.0
0.3102742761619154
0.0
0.9237308958024475
0.0
1.0426526858111589
1.469879159633073
0.0
0.0
0.8179323340267094
0.0
0.14993168542250726
1.2880650194645853
0.3998271635914176
0.3343766428803286
1.6665965569009276
0.4507258558220283
0.9136368809076364
0.569846538884429
1.008838547421102
0.0
1.128111181178282
1.377866533037425
0.8097419713901639
0.19793187978531648
0.6850120114514922
0.0
0.1623733443524409
0.0
0.0
0.0
2.3610785543561033
0.8276641838362718
0.7561232109776905
0.5257088774100598
0.9073806785264431
0.5253292267889704
0.2544694809382712
0.0
0.22642773471636832
0.8828024535117509
0.2082012808878749
0.0
1.6981007781817388
0.8044817041425255
0.0
0.0
1.0104324878754565
0.0
0.10206128995817358
1.5246811035354342
0.778998718632153
1.110986507162199
1.0423777539071406
0.0
0.8049313641100011
0.9320885219347439
1.905077106575817
0.08488164602937613
0.0
0.5027067254285204
0.8173020435366167
0.61296974908613
0.784202060521912
2.7051664578713086
0.7199583599039873
0.04265142327889032
0.4564066847220614
0.06559461105186093
0.0
0.5020572278514849
0.8607447680025434
2.178029554772173
1.1851155949891028
1.2114064381432994
0.7223912486700161
1.403521998307592
0.39021367680643737
0.3364548750057775
0.4019817895069839
0.0
0.45432375604446673
1.244876695311559
0.8607871322997782
0.9005982344310163
0.7134947696458626
1.0036598555018796
0.3203819049696535
0.7429246422512352
0.34317250224091805
0.24233858565092453
1.3080847670289077
0.8690741061146481
1.7062919741469849
0.18734424581933642
0.0
0.06555828127655275
0.6102501334043022
0.35068707571321545
0.0
2.0059625121937454
0.24352099123701326
0.08817736134347591
0.0
0.3747846069352336
0.8148165779700913
0.0
0.11836562374635023
0.0
0.2670655404791243
1.348558467010747
0.15945798330849137
0.0
0.23151342991735857
1.1012746907208968
0.0
0.0035835355077560123
0.0
0.5487045242477505
0.0
0.0
0.4023244844428509
1.1957141730673881
0.0
0.03958457761092098
0.9279256375588816
1.1307636106179455
0.9458201566229698
0.24091742666830046
0.6482430962720027
1.0789864187994236
1.6196387599319053
0.7471251010385039
2.1738781910592193
1.7283052486493116
0.6697430426575159
0.20102186839871294
1.645340686795362
0.0
0.0
0.0
0.0
0.13730322771580641
0.2695254529928567
0.0
0.18922191535132557
0.055461587532203434
0.03030239954761062
0.0
0.6594531458260361
0.06388925035766387
0.5293628599853714
0.4452215979603999
1.3036598243353417
0.7335491187683852
1.1465828169054435
0.6001819510085774
0.7576408766146409
0.8015659240338725
0.31870699572642963
0.7124350306683576
0.5448710802814337
0.7541727917095251
0.26809605080787086
1.0080896951712828
0.8071476726317598
0.9813429018506716
0.0
2.7103797067530375
0.0
0.4519206798646983
0.8448703241844429
0.0
0.0
0.0
0.605977991363913
0.7102116596594941
2.4985081943098977
1.4186814850255096
0.0
1.569360989631305
0.0
0.0
0.0
0.17231811750033674
0.5956901244296015
1.6440397480058326
0.0
1.580751852812343
2.5007764961758623
1.445306214715511
0.7383444195313681
1.1943697401023283
0.7421605464508737
0.0
1.7497749654083774
0.9228926114923544
0.8050397674498146
0.49005753574725425
0.984179473817076
1.3452284805638983
0.7180543158315156
0.40352262673708306
0.013073971770834938
0.0
1.7934989826403582
1.188470437520037
0.033163117993278944
0.0
1.3417641888619887
0.0
0.0
1.4334302287737668
0.4100189265171694
0.21165499539678825
1.3475934003521923
1.15596403813795
0.0
2.1669654813151715
0.7540360005285269
3.084228814503141
0.0
0.15913743298982605
0.0
0.8677845498748997
1.1224176566163524
1.7378996230504744
1.319456110988694
0.7726902234196451
0.0
0.22434834574165752
0.25622261135876745
0.0
1.6385348103504582
0.0
0.09414462455586363
0.5270365584806108
0.0
1.3800167264076908
1.4684281220676476
0.0
0.9207104972535329
0.20498130175460566
0.6237183900063473
1.0458565398069568
0.9911537822491533
0.2418320218512078
0.4396287407020645
0.0
0.4751301645802404
0.8068329136937618
0.0
0.0
0.0
0.0
0.20011282750336584
0.7077380586022649
0.36981938447702234
0.31179846679647577
1.1507206600418423
0.30121357619759637
0.0
0.4033527167562411
0.6653539960477387
0.44870067288093884
1.3319729715891238
0.0
0.6696940239984431
0.0
2.266394693815267
0.3508441227099207
0.9118704973118806
1.0126477233746238
1.2922191246421244
0.0
0.9782696005842115
0.2797093813973294
0.07549719264186407
0.05857174395360893
0.6410594975471346
0.0
0.3230450027952227
0.9633610999745922
1.2018751518823054
1.2292810585235066
0.9221054542966034
1.581146965496863
0.0
1.4377443635721263
0.9605739309493667
0.0
0.8183380269835427
0.8186986295757553
0.3146006181845213
0.5061763199327719
0.0
1.7028121524200426
0.4031752865230459
0.6579684823831357
1.2064917002311266
1.4746995581685989
0.6024119974854809
0.2904219439053847
0.0
0.4503041957080645
0.24128071226703413
1.976628479652881
0.4482164091179224
0.0
0.4541710863266604
1.296437169417908
1.251434546259519
0.0
0.7576020641653755
0.258893743535062
0.0
0.31621063154597256
1.1203709212609205
0.1775691067253127
0.7283630216096866
0.14115119237555482
0.46858726160563513
2.4791680842719237
1.5257497277517316
0.2014037026554737
0.0
0.08925448585375177
0.3707793876515025
0.9974131739830042
0.7378300723875449
0.0
0.0
0.545557831527581
0.886287232242104
0.0
0.051842767596724376
0.9005870279720791
0.7973000852266964
0.0
1.6188155720967805
0.07711032746747158
1.2038764102868893
1.7492927141008991
1.2269580075744122
1.0264743724886278
1.0474271371549078
0.722213770570776
1.2297806123502848
1.896351677143632
2.0674151758028056
0.8779779327834949
1.0273223317180322
2.5836910715544543
0.0
0.7834376887540013
0.7360470031148615
0.23010304901679285
0.08621229973618039
0.0022654662042719607
0.6921444978756655
0.0
0.6164101013022891
1.0908785879238654
1.348133215753337
2.0474465196751144
3.2415297286116274
0.1980130119224721
0.7549039831764167
0.545026477829646
1.5066340177410598
0.3717199587296843
1.0701435016877396
0.0
1.4859802928513255
1.8088339973830319
0.48452871774953843
0.6382842016613685
1.2564866492846367
0.5305555075388944
0.2062664469753946
0.9089790449774314
2.208945125995277
0.0
0.757018944056326
2.006047449377607
0.3600826840790498
1.2117758389472313
0.2806816872266235
0.0
0.0
0.642913380395254
0.34532996829392665
0.8552210548756207
0.27560746696447347
0.8644460892901126
1.3193566754966284
0.1549177511412324
0.3148242647819859
0.4565279825926584
0.37204976389826333
0.0
1.563919124940453
0.6792713793044864
0.0
1.780286756479792
0.3112618158187809
0.13932425566983295
0.0
0.7845329547939771
0.28942406462838494
0.0
0.0
1.4832875351612218
0.4450186494379993
0.40478551912611377
0.4415149625357849
2.0624246979206373
0.8836576555210955
1.8859655013886736
0.0
1.874468924737484
0.0
0.6348248781165334
0.0
0.0
0.4289464270881506
0.0
1.9712395788302874
1.2733125633085776
1.4655295956395158
0.41064041788274064
1.109189353460991
0.13067524036136563
0.0
0.39376741963585626
0.7260801385986486
0.0
0.05879659420007017
1.3718681477032653
1.3081417538190783
0.9057730609384613
0.48789487094170425
0.969211275134563
0.049108467755641705
1.3692564848553248
0.0
0.0
0.0
0.6861768243813636
0.33964825224096856
0.3268820846783066
0.7667539501498878
1.9325754332305176
1.1066089082768273
0.0
1.2896783322174712
0.27746625117114976
0.9537428404900855
0.0
0.29794739017323846
0.7281549644289346
0.1563817017416498
0.7565159614211007
0.6068602479800668
1.0262452210201078
0.0548878346241714
1.4190701163067023
0.8121012556353094
0.0
0.6657865430020464
0.0
0.1776249697986635
0.1714106702801155
0.21338466483906876
0.16780144243445616
0.12387263260534497
0.16135330797658975
1.7138984752701816
0.29394931576934247
0.0
1.2972941139856997
3.2628510480155186
0.4151898803972427
0.5036994582926301
0.0
0.0
0.022002938173545
0.04256764891600964
1.537789616609713
0.6445179817364375
1.2591843893618102
0.1489665874255706
0.0
0.4896811622133619
0.07803823355454995
0.5934926964795053
0.0
0.0
1.088085239163838
1.0060403791896833
2.8005154935328265
0.31850550860210425
0.75182596949525
accumulated_time=0.186079740524292

print(__doc__)
import time
import numpy as np
import matplotlib.pyplot as plt
import pytransform3d.plot_utils as ppu
from distance3d import gjk, colliders
from distance3d import random
from distance3d import plotting


random_state = np.random.RandomState(0)
center, radius = random.rand_sphere(random_state, 0.2, 1.0)

ax = ppu.make_3d_axis(ax_s=2)

accumulated_time = 0.0
for i in range(1000):
    center2, radius2 = random.rand_sphere(random_state, 1.0, 1.0)
    start = time.time()
    s1 = colliders.Sphere(center, radius)
    s2 = colliders.Sphere(center2, radius2)
    dist, closest_point_sphere, closest_point_sphere2, _ = gjk.gjk(s1, s2)
    end = time.time()
    accumulated_time += end - start
    print(dist)
    if i > 5:
        continue
    plotting.plot_segment(
        ax, closest_point_sphere, closest_point_sphere2, c="k", lw=1)
    ppu.plot_sphere(ax, p=center2, radius=radius2, wireframe=False, alpha=0.2)
print(f"{accumulated_time=}")

ppu.plot_sphere(
    ax, p=center, radius=radius, color="yellow", wireframe=False, alpha=0.5)
plt.show()

Total running time of the script: ( 0 minutes 0.363 seconds)

Gallery generated by Sphinx-Gallery