Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find closest point #111

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/Color.html
Original file line number Diff line number Diff line change
Expand Up @@ -15565,7 +15565,7 @@ <h1 id="Color">Color<a class="anchor-link" href="#Color">&#182;</a></h1><p><stro
let d = Math.hypot(dx, dy)
if (d) {
if (ev.ctrlKey | ev.buttons == 4) {
this.camera.rotation = mat.mm(mat.angle_axis(d / 100, -dy / d, dx / d, 0), this.camera.rotation)
this.camera.rotation = mat.mm(mat.angle_axis(d / 100, dy / d, dx / d, 0), this.camera.rotation)
this.render()
} else if (ev.shiftKey | ev.buttons == 1) {
const ratio = this.camera.height / 200
Expand Down Expand Up @@ -15771,7 +15771,7 @@ <h1 id="Color">Color<a class="anchor-link" href="#Color">&#182;</a></h1><p><stro


<div class="jp-RenderedText jp-OutputArea-output jp-OutputArea-executeResult" data-mime-type="text/plain">
<pre>Color([0.14557167, 0.5341767 , 0.50783263, 0.38952261])</pre>
<pre>Color([0.43867122, 0.71998605, 0.16290485, 0.0660278 ])</pre>
</div>

</div>
Expand Down Expand Up @@ -15810,11 +15810,11 @@ <h1 id="Color">Color<a class="anchor-link" href="#Color">&#182;</a></h1><p><stro


<div class="jp-RenderedText jp-OutputArea-output jp-OutputArea-executeResult" data-mime-type="text/plain">
<pre>Color([[[0.84278894, 0.68167057, 0.64182385, 0.02110083]],
<pre>Color([[[0.55231096, 0.82351175, 0.68167161, 0.61160467]],

[[0.04302143, 0.26156584, 0.16323815, 0.92268359]],
[[0.01292776, 0.91130699, 0.68297434, 0.59646707]],

[[0.11445908, 0.25017905, 0.80861133, 0.84190303]]])</pre>
[[0.78735723, 0.30805749, 0.33416277, 0.99788242]]])</pre>
</div>

</div>
Expand Down
31 changes: 21 additions & 10 deletions docs/Rotation.html

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions docs/Transform.html

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions docs/Vector.html

Large diffs are not rendered by default.

76 changes: 38 additions & 38 deletions docs/Vector3.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Vector4.html
Original file line number Diff line number Diff line change
Expand Up @@ -15564,7 +15564,7 @@ <h1 id="Vector4">Vector4<a class="anchor-link" href="#Vector4">&#182;</a></h1>
let d = Math.hypot(dx, dy)
if (d) {
if (ev.ctrlKey | ev.buttons == 4) {
this.camera.rotation = mat.mm(mat.angle_axis(d / 100, -dy / d, dx / d, 0), this.camera.rotation)
this.camera.rotation = mat.mm(mat.angle_axis(d / 100, dy / d, dx / d, 0), this.camera.rotation)
this.render()
} else if (ev.shiftKey | ev.buttons == 1) {
const ratio = this.camera.height / 200
Expand Down
7 changes: 4 additions & 3 deletions docs/index.html

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions py3d/py3d/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def M(self) -> Vector | Vector2 | Vector3 | Vector4:
@property
def L(self) -> Vector:
# length
return numpy.linalg.norm(self, axis=self.ndim - 1)
return numpy.linalg.norm(self, axis=self.ndim - 1).view(Vector)

def min(self) -> Vector:
return super().min(axis=self.ndim-2)
Expand All @@ -263,7 +263,7 @@ def max(self) -> Vector:

def diff(self, n=1) -> Vector:
return numpy.diff(self, n, axis=self.ndim-2)

def lerp(self, x, xp) -> Vector:
'''
linear interpolation
Expand Down Expand Up @@ -407,6 +407,22 @@ def projection_on_plane(self, plane) -> numpy.ndarray:
plane.normal[:, numpy.newaxis]
)

def closest_point_to_points(self, points: Vector3 | numpy.ndarray | list) -> Vector3:
'''
return closest point indexes of one point cloud to another point cloud, and also return indexes of the pair points in the another point cloud
both self and points should be flattened
'''
pts = Vector3(points)
assert self.ndim < 3, "self should be flattened"
assert pts.ndim < 3, "parameter `points` should be flattened"
d: Vector = (self[..., numpy.newaxis, :] - pts).L
d = d.reshape(*d.shape[:-2], -1)
idx = d.argmin(d.ndim-1)
spts = sum(pts.n)
idx0 = idx//spts
idx1 = idx % spts
return idx0, idx1

def as_scaling(self) -> Transform:
ret = Transform
ret[..., 0, 0] = self[..., 0]
Expand Down
2 changes: 1 addition & 1 deletion py3d/py3d/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
let d = Math.hypot(dx, dy)
if (d) {
if (ev.ctrlKey | ev.buttons == 4) {
this.camera.rotation = mat.mm(mat.angle_axis(d / 100, -dy / d, dx / d, 0), this.camera.rotation)
this.camera.rotation = mat.mm(mat.angle_axis(d / 100, dy / d, dx / d, 0), this.camera.rotation)
this.render()
} else if (ev.shiftKey | ev.buttons == 1) {
const ratio = this.camera.height / 200
Expand Down