Note
Click here to download the full example code
Distance from triangle to rectangleΒΆ
6.663263167866264
6.620451494154924
5.0254136427703395
6.190147660864652
5.461452130402149
6.011165455842734
6.024535536035437
5.086008601526886
3.924438577952539
4.674840361452802
7.1578248973224055
6.24901205524286
5.667390947803202
6.154672869216332
5.005416980349471
4.250803226415846
6.270910361448214
6.119436236762428
6.486149066300381
6.114742220385425
5.4821966660574075
5.881233015181912
5.557874764596542
6.470425207312655
5.909433203831306
7.371947716953546
6.337143040853737
6.605038507430196
6.097332588152918
5.785283350878427
4.948028290582395
6.238422593680928
6.079335592444758
3.9624245638860423
5.318882424076179
4.6252335961969075
4.867402176435599
6.863943097414874
6.5697665719273735
5.687089282560591
5.382899519243372
6.648837964666691
6.224778344256091
6.358226562383653
7.161947328724741
4.543584731237989
6.652265089214385
5.343387969804596
5.343283285483772
6.484210141313967
4.450818533907014
5.896651754386009
6.166320816186914
4.322602936183915
5.028394929671611
3.467570763246288
3.8704228423981726
7.017969521135937
4.181151726647664
5.731121942080196
4.288385360280055
4.855665232677517
5.309435705493595
5.7933631853343694
4.447133491119743
5.944074557177379
5.63052753459118
5.181291812948349
5.926254334546404
7.2086004117437295
4.042333300783114
5.385646024349397
6.472179195090788
4.739318291602197
5.542212277032708
6.2695909848474125
6.904892611716788
6.011194849428322
5.823582885604077
4.980134168124172
6.903730075588631
4.547614485086293
4.1176811776863325
5.339369991753619
4.971119825217
5.886771359330143
5.27663807013931
6.7304440396848095
5.233241205037431
5.774736212101533
5.940385753956579
5.142840994035289
6.9444452232203835
5.062188303122845
5.414513350535525
4.099090659957135
4.635075274780944
5.635466580111384
5.6846771393596525
7.138035536792011
4.795244179099446
5.783174818242746
5.075657298945977
5.494234283521283
6.496209580491996
5.90680113676839
5.219313234651279
5.1728550028845905
6.641873627640963
5.9749819239180715
6.146642333549809
5.948516604620913
5.6007716215461985
5.372657493671021
6.0529366738682295
5.975855322051831
6.257811577680667
5.104081771676132
5.497483863572293
5.181601614381356
4.923946910455392
5.443072983185588
4.894928650874908
7.121478691356477
5.704025004084507
5.100607824150656
5.064843165222433
5.745306393394896
6.381996216618957
6.234631474380256
4.899024124164635
5.1449166335161625
6.857887512073327
6.057541405329282
4.463389603171894
5.16774862809762
5.873823603999591
5.738764117800092
3.8530187365951845
4.772746895685171
6.506993558553964
6.592208312037455
6.801450297603603
6.147101926770202
6.350059866356921
4.600890400593594
5.071121486115784
5.782954984047586
5.635287031964046
3.7871359114913314
5.8270727502703075
5.273085551917322
4.869930999072476
6.25994419181488
5.667769070854697
3.692756104244592
4.443694903288438
5.3636792405555624
5.586102732238168
4.416375810715091
6.544777027946168
5.161393070521337
5.767466998500056
4.152706887447877
4.910517244824385
4.0858490888359205
6.216057113823765
5.1008053731881455
4.128424260672453
4.25834570539108
5.877758471126855
6.130055976140577
6.597584988289635
6.66795369648994
5.7284613913080245
5.570444038795416
6.436716285735493
5.2125831431841
5.129898485402828
5.258684463160236
5.4757086597120646
5.265225377042041
6.717714026047795
4.566207383302013
5.710863132241441
6.5619282861371495
4.703334650644583
5.930804084301285
5.77979215333069
6.621134464820594
6.019150023260013
6.890556382278088
6.936858577352931
6.1421358500963965
4.382498238839948
6.161124593558271
6.665434710623694
5.005056834307003
5.214530372335603
6.346909525965858
6.824459945204883
6.790571373527774
4.690761733515604
5.939849212144846
5.504969054140836
6.885880421498363
5.486109243311695
5.247474753792838
5.10705196235224
4.128586680972864
6.095175804203442
5.642478146377926
5.157126028793603
4.9044458582634824
4.208396239808149
6.7928809194988435
6.427044292086098
4.051050456182694
7.03456983196135
4.880522766002614
5.423588695149807
7.190173191678034
6.632059170290242
3.281603777822378
6.003818406282189
5.532711478231926
4.528596805746792
5.642908141861249
6.09480836265617
6.176462481044537
5.142706864286634
6.888796715600987
6.033423524248781
6.184792978831997
5.878834985499451
6.307044239383231
5.395761804358525
5.953375745857713
5.185260963516966
4.253896068146431
5.4966463061946005
6.185257109475772
6.03838532748044
4.9957779204174395
6.175162287619223
6.429057580926837
3.6900185363142626
5.496638465183157
4.289098776471309
4.921064474632153
5.204463712374261
5.078453535939331
5.190993770631952
4.772926624866624
4.2485820736940365
5.306302649267112
6.078550825646975
5.724785917381073
4.676284976842801
6.452957155650637
5.332578117824182
4.046258632114183
6.077735691045945
6.009422550020166
5.2973720098099335
6.650184421793824
4.198775505322443
4.21680114698894
5.991577726294784
5.002543707364825
5.19996376609024
5.705152127453359
4.371243355461529
4.920191032778528
7.277068992274106
6.448235841201834
3.6807197356513126
5.79486044615968
5.1667266989301925
5.607969931787474
5.804001137169166
5.517884572600521
5.255963311641255
5.650058475725918
6.233875834033337
7.326038118992107
4.781656218056533
5.0000256947172295
4.781341839937506
5.706135408587873
5.759740626880882
6.460209822772351
4.479872778765807
5.508524195738025
3.727477344395849
7.116065951575995
4.237906283277304
4.71248625863767
5.234363436839192
6.153924326463494
6.065355506466657
5.590871381645345
4.7709689583000765
6.808434437246332
6.136676833893655
4.029552833865121
4.851623332315698
5.281155033556662
4.751371370676579
4.492067405628679
5.003441288187958
5.146333145935446
5.423120189070221
5.683249876794519
6.7831933930321275
5.453059579881214
4.9313935182746516
5.296032363149076
6.377868139664459
5.577382540279326
6.830688708673649
7.484998820717731
5.35281437152454
5.164837052843608
5.168897333476612
4.427097840519066
5.126965326665677
4.96255984141248
4.6196075122969775
5.01549598346403
4.407750672987481
6.597134652525825
7.525874282226668
6.278005412179052
7.3744324647128785
6.880872288244909
4.213934342783348
6.67726704646825
4.23956082867534
5.846041414483505
6.775294471765709
3.4880784489927454
5.643126209177947
4.483203878538007
5.390082986324256
6.823614525125187
4.477769604379396
6.282281146103598
6.419686712332136
5.217039074042381
5.014801263976395
6.038218439730137
5.50775159082465
5.920482060676963
5.850075959661062
3.834434550559558
4.974553376852373
5.83398634760554
4.5100137394230195
6.4299290928902915
4.611380938099466
7.185178527044396
6.705976020388584
6.153302526136738
5.795775225836978
4.474846215352932
4.866898549280099
4.524249748443711
3.717019605173731
5.955695351113923
3.9110276998924576
6.812313572087036
5.006500301863917
5.949335694738737
4.963548949276635
5.451030150854591
6.449004405336847
5.422539992349679
5.670828591815854
5.053659636139717
5.859959758822081
6.661023937273253
4.759176812173522
4.177881212716196
5.2644684973152005
5.555752048218447
5.1365363403720625
6.553097023611798
5.90821188308126
5.3022337641889115
6.004567493222152
5.903871451582534
6.0104605347902025
4.498469312295014
3.9963767722928027
6.527749743638512
5.4086758297507025
6.185735328074123
4.783030133416893
5.181286210231974
6.223947121162697
4.691770988536174
4.22043197267834
4.930785833589046
5.1305337951222505
5.222867211304069
5.0182503906714455
4.953600770150192
5.036435694500501
4.895691035531025
6.376307485192442
5.512137257384709
5.0563569380703655
6.581323027369523
5.893912006233117
5.464217041382864
5.83829973326613
5.762373214549264
5.987690831274927
5.501704306118121
4.8141386256797345
3.6559935519722537
5.925460417928339
4.660467616512611
5.070991295625501
4.374229661797736
5.557827588050167
6.831964217468782
4.143516625820795
4.127023232436393
5.721293814172368
5.3819057816551235
6.390677379927157
6.496660880109824
5.661012869413935
6.070308471820759
5.276035493636822
5.846462345464386
4.418921957231003
7.382462155236473
6.600104694745518
4.757263784554507
6.1815392311750506
5.782555038877227
6.69630271686141
6.621658149540745
6.142463545452476
4.331901136436617
6.717157911922593
5.248966169464044
5.091963466688963
4.426367275309557
7.499523941315182
5.881436078386498
4.25986923425689
6.39238364305666
6.533829227169684
5.592763506056766
6.105364481856636
5.676411107364189
4.220667531941028
5.542337133562106
4.762638045251722
6.151091909552819
5.896102286776354
6.135614039981978
6.0321904790019305
5.214808232096226
6.027893978582771
5.249726797193651
3.4612719263526928
4.1451624761309915
5.594940134657084
6.0344972308160285
5.2577158280606415
5.94931335592656
4.173681206554909
5.998060473292228
6.568920869688464
6.138238282928872
4.810471078616376
4.329299688540618
5.416383104133364
5.974275122609913
5.052463641032344
4.78328343429115
6.205163666312592
5.831316379834345
6.681820101406175
4.214685154629401
6.573236753842403
6.074018498039427
5.542644182384316
4.047049801346209
5.0427083803366495
6.716524684136389
5.413425415138836
5.28634643910678
7.0021941232332585
5.803300349909474
6.13346051714116
4.188410019662027
4.977785024847874
6.5327100690311966
5.741715342852593
4.689317471002924
5.836378633529665
6.1579222819449955
5.01591916872657
6.394468932369207
5.568814243956738
6.55659712410789
5.09884872163241
6.4199543962714305
4.939326288753996
5.237756916111957
6.874137004195179
5.855699077465316
4.534568102111141
4.8567703562559394
6.08858163114189
5.043173071734502
4.442217082169071
7.0993677780521205
6.991001268739435
4.582345296344894
4.54506619046151
4.283448072249515
5.02051161945983
4.372691834007295
3.862677523351557
5.108965481106052
5.259428489414481
5.501002500948763
4.615872806338099
4.642024290545985
5.781150132035785
6.277494792669957
4.5957691502448075
4.319164456550196
6.279438619451194
6.576655436141962
4.163811458706421
5.942754498889344
8.078214750358214
6.481143830616535
5.231070233877681
4.85839960879289
5.291134156398555
5.727927843573781
6.250810564040511
4.911642155452588
5.693506636258502
5.919656923600796
5.079979953703148
6.210429800468299
4.565439631692262
5.221734209992493
6.0668528590034105
5.734160350203828
4.665993826904063
5.695466629436206
6.234058949407946
5.1111393892170955
5.231130136894896
5.397238818544829
5.329286672155203
4.314381176557161
3.786793335649515
6.358040683894754
5.888543800339154
5.394986283029997
6.523563383723033
5.144691290252296
5.417709556832767
7.5442329737487395
6.289720832188714
7.907218931107982
5.46613650217322
5.7261011517442135
6.140870720444898
6.453990055774935
6.55424471736779
6.389100446553217
4.946568486954931
5.760756341718078
5.2338336272489725
6.8701809809963414
5.347843484196216
7.39469059306978
6.308145871772757
6.0112882118442705
5.099691593585961
5.364016526936662
6.468316029525912
5.699527311338514
4.807450954367475
4.8263856032560755
6.564836078422294
6.493220769678991
5.273317697216734
6.050868157427316
4.98575612151026
6.160149536817998
5.6654394218759885
6.5055181701071225
5.482894217875142
3.5526864962724902
4.970331574740044
4.581006521966352
4.8759428469754225
7.5384640776024145
6.598572234342563
4.957360472552443
4.301377349726539
6.250540579398975
4.123102900673419
4.776216537693662
6.752193671240726
5.436628998930975
4.8429356705977975
6.025873186277755
6.43813866490147
6.096174021404576
4.702640343731575
5.172216599301155
4.6072191170873324
3.867423534184336
5.653092962390717
5.48448023189008
5.240152243104777
5.540746008752436
4.552504408510912
6.267817999042125
5.081103924847497
5.467960876656982
6.273129959908845
4.970132395381049
5.018538969268887
5.718895132091375
4.8106892163689885
7.365161474918164
5.997205343181471
6.155682808925041
5.884054410062435
5.989755716314991
5.566533989761145
6.770285941140668
6.596520304171837
5.861377461583599
5.8711870850553245
4.227995948969664
5.655682948943001
4.986108419884486
5.8261131488500615
5.938594189261724
7.006343891248397
7.014577349465197
6.348593404529907
6.232297630112455
6.71812931009951
4.932973186029174
5.433068707387594
4.639375202418465
5.126685870926708
4.291066370630654
5.83745231222284
6.376420583530402
5.203414237193609
5.107141142845526
4.956135359697381
4.909315134149817
6.116611291445033
5.672092894919335
7.1237010526347895
5.216528939477389
5.486743745733127
5.9553913967238525
4.995506172558318
5.641623299084797
5.684623884877378
4.773258339698826
3.737368576317842
4.489712913927945
5.656742177722129
2.931153828553119
6.562730573504751
4.66828380493462
6.6684910021588735
5.546201248580438
7.821868649318245
6.124646424255492
6.765333741911398
4.783129123498171
6.173142397075475
4.753559297987337
4.885016767119993
3.7796335074360776
6.603409917732008
6.270965852837673
5.450618201375145
5.172732153031163
6.102751073414153
4.38034468740436
6.714509207245403
3.507674959820011
5.984574319697297
5.760235455946154
3.867885428776779
6.634712723706605
5.478412003747473
5.402745941496559
3.1472622516609547
5.552891339941335
5.657400020016308
5.119480785792103
6.154874633961313
7.654255399491674
4.666026573269313
3.893322577319018
6.282195989537366
5.803164698627862
6.272508891760396
6.149390895179477
7.392259422035144
5.974225497480316
4.784609538380887
5.201458715679737
4.962630221840091
3.2728291545886314
5.036330275392502
6.011067993789353
5.519373702949088
3.121431505136116
5.486178558135108
5.063176528584794
5.532009452545358
5.821093974441565
5.786337777238547
6.997934830652269
6.181232471750211
5.9687799197860585
6.004517846948505
5.7069533471713285
6.8645385055252754
5.324771636936303
5.266421863884519
6.032227013751767
3.410921926723591
5.453608920704983
accumulated_time=0.24726295471191406
print(__doc__)
import time
import numpy as np
import matplotlib.pyplot as plt
import pytransform3d.plot_utils as ppu
from distance3d.distance import triangle_to_rectangle
from distance3d import random, plotting
random_state = np.random.RandomState(0)
rectangle_center, rectangle_axes, rectangle_lengths = random.randn_rectangle(
random_state, center_scale=0.1, length_scale=5)
ax = ppu.make_3d_axis(ax_s=5)
accumulated_time = 0.0
for i in range(750):
triangle_points = random.randn_triangle(random_state) + 4 * np.sign(np.random.randn(1, 3))
start = time.time()
dist, closest_point_triangle, closest_point_rectangle = triangle_to_rectangle(
triangle_points, rectangle_center, rectangle_axes, rectangle_lengths)
end = time.time()
accumulated_time += end - start
print(dist)
if i > 10:
continue
plotting.plot_segment(
ax, closest_point_triangle, closest_point_rectangle, c="k", lw=1)
plotting.plot_triangle(ax, triangle_points, surface_alpha=0.8)
print(f"{accumulated_time=}")
plotting.plot_rectangle(
ax, rectangle_center, rectangle_axes, rectangle_lengths, show_axes=True,
surface_alpha=0.1)
plt.show()
Total running time of the script: ( 0 minutes 0.376 seconds)