Distance from rectangle to boxΒΆ

plot rectangle to box
6.5459933136461625
3.0701908026469797
3.077286995231373
1.7348465617487863
2.26477819301613
0.37996293831538
0.9488693004891864
1.609089581154274
0.0
0.333330866193465
4.450758276592122
2.285955167058807
2.0643617421023177
4.269428834247569
4.018655640625866
0.8226733406621075
1.1269066556950236
2.481606507920645
2.800096362539799
4.341693818447528
2.905733870184981
1.6335966278228944
3.863103079625139
0.4087598392643504
5.1454834660308455
2.2447747323350935
0.20678172071400422
1.9224523172636656
1.439792130223434
8.71613338107439
0.1705697106200064
1.0709680162230173
4.410702852678489
1.1896067088857587
3.2387347973114733
5.14881727857126
2.3091043282097514
3.1200239782465955
2.0492029227670923
2.3013629532978057
0.8347003829006441
1.0157958244290768
0.4782036998448275
2.6055448896362443
5.53963856615807
0.9854168274388665
4.911127698416321
3.81179969620882
1.9495683714417682
3.2827698383225887
4.63153616152986
3.245818784810988
3.0447110123320984
1.852725727791475
2.349553778085546
2.841246235901499
3.232954212307242
1.9455559772684623
1.8105410472601893
0.47186518865670896
4.2665015240717405
3.777426590186438
5.481530173821726
1.641327815939052
2.432684585295822
1.1871772006876933
1.546372631406054
4.122214223551843
4.521266381635317
3.422911438306334
1.2045921604562506
1.9132667967368422
2.379871573769592
4.681262242371754
5.85265074588807
2.3015851599940347
2.901430220144829
1.0134399632774247
4.397265863846494
1.9921720288028288
1.5008162887070358
1.6165207813836076
1.5525134163809562
0.4371782664056468
0.11055986267804845
1.7239962945070049
2.2698770849473147
2.0888915694171954
2.8800120141875034
2.394860883388915
accumulated_time=0.3853800296783447

print(__doc__)
import time
import numpy as np
import matplotlib.pyplot as plt
import pytransform3d.transformations as pt
import pytransform3d.plot_utils as ppu
from distance3d.distance import rectangle_to_box
from distance3d import plotting, random


random_state = np.random.RandomState(0)
box2origin, size = random.rand_box(
    random_state, center_scale=0.1, size_scale=2)

ax = ppu.make_3d_axis(ax_s=5)

accumulated_time = 0.0
for i in range(90):
    rectangle_center, rectangle_axes, rectangle_lengths = random.randn_rectangle(
        random_state, center_scale=2.5, length_scale=5)

    start = time.time()
    dist, closest_point_rectangle, closest_point_box = rectangle_to_box(
        rectangle_center, rectangle_axes, rectangle_lengths, box2origin, size)
    end = time.time()
    accumulated_time += end - start
    print(dist)
    if i > 10:
        continue
    plotting.plot_segment(
        ax, closest_point_rectangle, closest_point_box, c="k", lw=1)
    plotting.plot_rectangle(
        ax, rectangle_center, rectangle_axes, rectangle_lengths,
        show_axes=False)
print(f"{accumulated_time=}")

ppu.plot_box(ax=ax, A2B=box2origin, size=size, wireframe=True, alpha=0.5)
ppu.plot_box(ax=ax, A2B=box2origin, size=size, wireframe=False, alpha=0.5)
pt.plot_transform(ax=ax, A2B=box2origin, s=0.1)
plt.show()

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

Gallery generated by Sphinx-Gallery