I am rendering a point cloud. In that point cloud I want to use mouse to drag and draw a (resizable) rectangle(for 2d) or cuboid(3d) and select all the points inside. I am new to python so dont have much idea about it.
I would be kind, if you could direct me to some libraries or packages or anything which will help.
I am using (python) Jupyter-notebook using matplotlib for rendering the data. for starters I am able to draw a rectangle
What I have tried:
<pre>
import pandas as pd
import random
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
#point cloud coordinates
points = [(random.random(), random.random()) for i in range(20)]
pts = np.array(points)
# X and Y coordinates that is tö be fed to scatter plot
xcord =[row[0] for row in pts]
ycord= [row[1] for row in pts]
print("Enter the cordinates of the rectangle")
numx1 = input('x1 lower cordinate: ')
numx2 = input('x2 upper cordinate: ')
numy1 = input('y1 lower cordinate: ')
numy2 = input('y2 upper cordinate: ')
numx1, numx2 = sorted([float(numx1), float(numx2)])
numy1, numy2 = sorted([float(numx1), float(numy2)])
ll = np.array([numx1, numy1]) # lower left cordinate of rectangel
ur = np.array([numx2, numy2]) # upper right cordinate of rectangel
inidx = np.all(np.logical_and(ll <= pts, pts <= ur), axis=1)
inbox = pts[inidx] #points inside rectangle
outbox = pts[np.logical_not(inidx)] # points outside the rectangle
figure1 = plt.figure(figsize=(8,6))
ax = figure1.add_subplot(111)
#Create a Rectangle patch
#Rectangle(xy, width, height, angle=0.0, **kwargs)
#rect cordinates a,b,c,d
# a =numx1,numy1 b =numx2,numy1 c =numx2,numy2 d = numx1,numy2
width1 = float(numx2)-float(numx1)
height1 = float(numy2)-float(numy1)
rect1 = patches.Rectangle((numx1,numy1),width1,height1,linewidth=1,edgecolor='r',facecolor='none')
# Add the patch to the Axes
ax.add_patch(rect1)
plt.scatter(xcord,ycord,s=2)
plt.show()
for example i made a simple program with random cordinates and this is result :
https:
I am expecting result something like this for 3d:
https:
I want to drag and draw the shape and should be able to resize. I will do further computations on the cordinates or shape accordingly.