mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-08-02 11:52:50 +08:00
Fix squared distance for CPU impl. (#83)
Summary: `PointLineDistanceForward()` should return squared distance. However, it seems that it returned non-squared distance when `v0` was near by `v1` in CPU implementation. Pull Request resolved: https://github.com/facebookresearch/pytorch3d/pull/83 Reviewed By: bottler Differential Revision: D20097181 Pulled By: nikhilaravi fbshipit-source-id: 7ea851c0837ab89364e42d283c999df21ff5ff02
This commit is contained in:
parent
a0f3dc2d63
commit
f358b9b14d
@ -271,7 +271,7 @@ T PointLineDistanceForward(
|
|||||||
const vec2<T> v1v0 = v1 - v0;
|
const vec2<T> v1v0 = v1 - v0;
|
||||||
const T l2 = dot(v1v0, v1v0);
|
const T l2 = dot(v1v0, v1v0);
|
||||||
if (l2 <= kEpsilon) {
|
if (l2 <= kEpsilon) {
|
||||||
return sqrt(dot(p - v1, p - v1));
|
return dot(p - v1, p - v1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const T t = dot(v1v0, p - v0) / l2;
|
const T t = dot(v1v0, p - v0) / l2;
|
||||||
|
@ -445,8 +445,8 @@ def point_line_distance(p, v0, v1):
|
|||||||
|
|
||||||
v1v0 = v1 - v0
|
v1v0 = v1 - v0
|
||||||
l2 = v1v0.dot(v1v0) # |v1 - v0|^2
|
l2 = v1v0.dot(v1v0) # |v1 - v0|^2
|
||||||
if l2 == 0.0:
|
if l2 <= kEpsilon:
|
||||||
return torch.sqrt((p - v1).dot(p - v1)) # v0 == v1
|
return (p - v1).dot(p - v1) # v0 == v1
|
||||||
|
|
||||||
t = (v1v0).dot(p - v0) / l2
|
t = (v1v0).dot(p - v0) / l2
|
||||||
t = torch.clamp(t, min=0.0, max=1.0)
|
t = torch.clamp(t, min=0.0, max=1.0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user