Note
Click here to download the full example code
Distance between cylinders with GJKΒΆ
2.243039428954227
0.8031517821069004
1.1400393856945301
0.8862269867562075
1.2529675455514613
0.0
0.0
0.5262912523636525
0.0
0.0
0.0
0.688494793612655
0.6416075186352608
0.5808560952159204
1.7408297515211661
0.0
0.0
1.191645797033626
0.0
1.9067076162870764
0.0
0.03043809915368195
0.2752463350178348
1.0783138825784206
0.0
1.3696943993974644
1.5817052518866848
0.2852468334367853
0.085785186392964
0.7081828713609788
0.0
1.220496170527859
1.0799553416753063
0.0
0.0
0.3662992264089779
0.06841623683487619
0.0
0.2479886091613126
0.20471011477162254
1.3726601485647212
0.0
0.6985981676693663
1.5687823247292634
0.5033137610002604
0.7320375113136813
0.8672940222760427
1.7088396597687754
0.0
0.0
0.811896655627643
1.1014637572366377
0.1320454298964189
0.0
0.8206494328267133
0.39672811099796673
0.0
0.6664318363882222
0.3803913447505262
0.6489097597368203
0.0
0.0768817581307835
0.0
0.0
1.140840278310309
1.2639193680707355
0.39452071204907396
1.2192482355904428
0.5165897422986079
0.29398412069664065
0.0
2.6606364595945746
0.0
0.0
0.8515311709904217
0.0
1.4155795691990882
0.41511444589676366
0.7792333409732023
0.8516708423608346
0.37525249830622465
0.7270673931437908
0.0
0.0
0.37240511847999946
0.0
0.10401481866075055
0.7407246744104813
0.2145191735174021
1.84669888043735
0.4306303492991331
0.3959953139200664
0.7642781677144157
0.4622855766625065
0.752553496768473
0.07363530224497417
2.746806560335343
0.0
0.06213470694391426
1.3402950447576236
0.07239748739741987
0.0
2.160293377728325
0.0
0.20373340108619703
0.4684289985469653
0.0
0.0
0.0
0.0
0.0
0.0
1.4392148631242687
0.0
0.0
0.5153175513641731
0.5274261729668853
0.769176589647558
0.0
0.951362763406929
0.07619304778500981
0.012095108881293844
0.0
0.08342373241837887
0.36905893076263335
0.33326818465083075
0.30767434315222264
0.9613248260037087
1.2387994123348927
0.38968600140413723
0.0
1.2900468837000814
0.0
1.01151043885688
0.0
0.35266519940515967
0.0
1.4265358114217919
0.9894454643935858
0.11421773094202806
0.0
0.32610150920782127
0.0
0.6011495108835592
0.0
0.0
0.0
1.084051403632885
0.8148057615321669
1.3330515933172393
0.032171594038015595
0.6656277721397781
0.3475397004248041
0.6960399953472544
0.7234022748301985
1.1961286236550388
0.0
0.0
0.0
0.0
0.31698530028113253
0.0
0.0
0.0
0.5919918147135993
0.9284727463132141
0.0
0.14001354550092587
0.04406346621197805
0.19200336601491583
0.0
0.5027639789818819
0.8649137296255843
0.0
0.0
0.0
0.0
0.7706876639024581
0.4433408553951782
0.0
0.0
0.0
0.0
1.3479135216367135
0.6107311939922184
0.5093123547201764
0.0
0.0
0.0
1.3680253729473162
1.1616874965747057
0.21212896690518412
1.4683930195361397
1.6479808895235892
0.0
0.47769680529467134
0.6217230013380715
0.5328242804853904
1.2742274694752724
0.12706274811870755
0.0
0.0
0.28907891852265105
0.22451282592138133
0.17234281406507024
0.0
0.0
0.2728395422848766
0.7043107537384924
0.3241198637116215
0.8190328704455986
0.8628411531323079
0.7478586048211605
0.4709212474789179
0.0
0.0
0.29781918971087773
0.7616494664902297
0.5579182528996969
0.18110498574644288
0.1761248619579476
0.6469001659736641
0.9242370087074946
0.23466110758618297
2.6731801257480674
0.0014756690234401094
1.8714814989158715
0.37469277244353555
0.5662840314892891
0.7199037352602218
1.1543923555151079
0.2600766055186461
1.1779820814029855
0.6641775694170162
0.0
0.23117723644459973
0.0
0.21647850653129003
0.9375316904759793
1.7025510338640133
0.9220790588512746
0.29651931672055293
0.0
0.24967607068158634
0.0
0.4201204739046133
0.0
0.0
2.015977999198685
0.0
1.719538831955502
0.0
0.5433222087115298
0.043887574762519685
0.46937808281714044
0.23733721914534076
0.321054837524951
0.6507014792663098
0.5253879257348566
0.08363817756722346
1.5954136508022994
0.0
2.2299111685325634
0.0
0.258241116802342
1.4707553958671875
0.13329286134376414
0.8395029175128067
0.0
0.0
1.760316730827065
0.4661897163167875
0.41154976345922034
0.5691365346749314
0.5932417296311885
0.39966983383987686
0.8535754599554791
0.057324309049736615
0.3852810335416515
0.9732012024615934
0.3265441680971805
0.0
0.1858900262326097
0.0
0.9539651201993729
0.0
0.0
1.0788025449426193
1.999577239545798
0.04612287375003593
0.5998598945513789
1.38883685948744
0.0
1.4062169567256586
0.738891223143216
0.0
0.8241697802975834
0.0
2.8079012125322325
0.0
0.0
1.129043500142341
1.4048861009465599
0.0
1.25053666384015
0.0
0.6196248824228193
1.095273815825558
1.713751098949962
1.64283153551242
1.0871997222351248
0.05341934581125498
0.0
0.3232580574754631
1.0775154276987031
0.6913525862695479
2.606411824354114
0.32658848686695785
0.32870369577980546
0.599052770266104
0.7298878013517346
0.5964326304404732
0.01454075824982643
0.0
1.5039591636543816
0.8426613449127573
0.0
0.0007201780034060427
0.4773709419862955
0.7758871270930555
0.0
0.8085725131243653
0.4031596893486165
0.0783674476550123
2.234420576481652
0.9717072217992587
0.34790334934415806
0.31287119273299474
1.4491449014425344
0.1766197545607033
0.0
0.6405798585398168
0.281266238627121
0.0
0.11432363258703931
0.09490705768866879
0.0
0.25854254791022824
0.33814749260883425
0.09302757237663344
0.0
0.3925204770631554
0.0
0.7573444976517337
0.0
0.0
0.49106049891722736
0.7445012232685237
0.6781164869822831
0.0
0.16896774289513833
1.3609192553375324
0.4479324950130501
0.0
0.0
1.010929976719168
0.9476235630397758
0.5575997453356734
0.6108267134739912
0.9036740693809595
0.0
0.0
0.0
0.0
0.9861396503912261
0.0
0.32892011005680194
0.3875682401407856
0.0
0.0
1.1209599471323795
0.654212328887117
1.296327067427372
0.0
0.0
1.740584469990925
0.24356975742214468
0.0
0.9363833060479544
0.7403679936160749
1.0669853171301622
0.0
0.0
0.5765204210858351
0.1648639316075842
0.0
0.28138875278310194
1.158200191513105
0.5462433160965375
0.5186684760156374
0.0
0.8635368517642356
0.0602585791812444
0.36167521461485774
0.0
0.0
2.562642185910511
1.0195840252222406
0.2963374751126669
0.6279525390616768
0.0
0.0
0.24142235980549595
0.879219943140814
0.024175291913419276
0.0
0.0
0.26148082533403305
0.5315492834442146
0.0
0.1737710265605459
1.0756561190512655
0.3792110710963829
0.0
0.6867388027722143
2.8750744948662583
1.305329130830089
0.0
0.6661488615297346
1.5877537627415164
0.32352327507585993
0.2996160233256923
0.0
1.7321374345817266
0.019091849028436178
1.6234442363498924
0.0
0.0550936604080115
0.13203397728515537
1.6246932551971587
0.7065944679391614
0.735680574296781
1.0160606841537203
1.3891387133207265
1.1598056328962298
0.8783729497658584
0.38798413375782015
0.7512965680733309
0.04608753100482278
1.6266017965046047
0.3512082237643449
1.3321525200179527
1.60562218456344
0.5849928604711724
1.5612641259184654
0.36532610753357564
0.09598378366731326
0.053379091523302696
0.0
0.6297362520225724
0.9077390569964234
1.0422247814642873
1.2871775462155886
1.6649185452288633
0.0
0.5453451811126502
0.24754311735021256
0.27840566142433726
0.0
0.2899039581127683
0.6352626538998115
1.5009195723804563
1.2051541322254227
0.3771719245836018
0.0
0.004812883975500035
0.2805620460404174
0.19777829196876517
0.17852714658943847
0.7974015629641473
1.05255383455709
0.17974055798473976
0.0
0.10779295155197118
1.0896660191119858
0.7147645910299476
0.0
0.19610960939463046
0.07049418466147916
0.0
0.0
0.0
0.0
0.0
0.15311243635656763
0.26975090775349575
1.2790130525190058
1.0037350435765786
0.5233173308587028
0.10838773407617176
1.231078132350518
0.0
0.5454859744508596
0.12656285485293592
0.19835977492303253
0.0
0.10388290350652067
0.5721258415841963
0.0
1.1893017994741786
0.0
1.3231943907123238
0.0
0.07734068634312732
0.01552866468090633
0.35422725168712094
2.259983162847468
2.136456076038549
0.15192405909136203
1.298458057657716
1.1371101955239773
0.8249329879200389
0.10870595318264613
0.0
0.0
1.3364541352474923
0.8899030748284743
0.026237719667029483
0.0
0.0
0.0
0.9586306431706844
0.10210899361450855
0.0
0.21494145342515145
1.5585528591162081
0.34305782098479287
0.0
0.8865261474778962
0.946996661698826
1.26348097573768
0.9052256397330953
1.4094115503439113
0.5611754624050141
2.3350786651556454
0.0
0.0
0.0
1.1500461386757914
0.16778988493819752
0.8809485188397094
0.0
1.388117729302691
0.3349894271053928
0.0
0.710466870378992
0.7405665479498494
1.3552759414449966
1.9736581729698475
0.6813923675628427
0.0
2.1249588775839974
0.6179962334789093
0.0
0.2880626144149519
0.09080799040734708
0.0012955022959829335
0.6860547783706644
0.0
1.8227507267079446
0.11564197851711247
1.459840395084628
0.0
1.188323752799217
0.2596079693127412
0.6340384738625572
0.0
0.5203612320054444
1.3410510780078801
0.5325310639419317
0.10506464425858288
0.2970768991981773
0.30229510233855916
0.6336379777646625
0.0418631389421897
1.197138751142492
0.8757141517110313
0.34013004248322
0.0
0.7919244248006471
0.0
0.2273418621780592
0.715986149446374
0.1804583136663782
0.7570164447987365
2.0620233839171966
0.0
0.0
0.0
0.0
1.1543528164705024
0.4739729598513023
0.6723483287281753
0.6454923227765708
0.0
0.6526245399991798
0.7105232988355947
0.0
0.057136816831562534
0.0
0.0
1.5775959955220067
0.06850368295615937
0.0
1.3542762340727357
0.11617093665649252
0.005848588100609596
2.0261725869364917
1.3616285770192114
0.0
0.07287764447061043
0.0
0.0
0.6404829800749454
0.0
0.0
1.276063974235803
0.0
0.6338214360145001
1.2129482783425847
1.0600398230804713
2.567848954380723
1.0927918502491218
0.0
1.7571956622246894
0.0
0.2505349198433121
1.5739342706573818
0.0
0.0
0.0
0.0
0.0
0.0
0.15523512209095564
0.0
0.8205928268602594
0.0
1.5442003426120527
0.8275106395323842
0.003460411740093321
1.1957441530749355
0.022173991878308572
0.2643683776338305
0.0
0.681986055272348
1.0658328191809616
0.0
0.4776733524295989
1.096711066732586
0.0
0.0
0.0
0.0
0.0
0.7666367352773519
0.878111080103272
0.0
0.0
0.5966622664727776
0.30208577000924763
0.22859606200838375
0.0
0.0
0.0
0.0
1.235898664289881
0.9957529544985084
0.0
0.0
0.30304437240335963
0.5233637209386229
1.1900498562096151
1.4450826716472545
0.0
0.0
1.1657805745800895
0.0
0.0
2.162507715215035
0.4943097518651862
0.0
0.0
0.964608332086741
0.0
0.0
0.6494675115580235
0.0
1.341221595869621
0.4186899125914839
accumulated_time=0.11375904083251953
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(1)
cylinder2origin, radius, length = random.rand_cylinder(random_state, 0.5, 1.0, 0.0)
ax = ppu.make_3d_axis(ax_s=2)
accumulated_time = 0.0
for i in range(700):
cylinder2origin2, radius2, length2 = random.rand_cylinder(random_state)
start = time.time()
c1 = colliders.Cylinder(cylinder2origin, radius, length)
c2 = colliders.Cylinder(cylinder2origin2, radius2, length2)
dist, closest_point_cylinder, closest_point_cylinder2, _ = gjk.gjk(c1, c2)
end = time.time()
accumulated_time += end - start
print(dist)
if i > 5:
continue
plotting.plot_segment(
ax, closest_point_cylinder, closest_point_cylinder2, c="k", lw=1)
ppu.plot_cylinder(ax, A2B=cylinder2origin2, radius=radius2, length=length2,
wireframe=False, color="b", alpha=0.2)
print(f"{accumulated_time=}")
ppu.plot_cylinder(ax, A2B=cylinder2origin, radius=radius, length=length,
wireframe=False, alpha=0.5)
plt.show()
Total running time of the script: ( 0 minutes 0.411 seconds)