lygia
/geometry
/triangle
/signedDistance
)Returns the signed distance from the surface of a triangle to a point
Dependencies:
lygia
/geometry
/triangle
/triangle
.glsl
lygia
/geometry
/triangle
/normal
.glsl
lygia
/geometry
/triangle
/closestPoint
.glsl
Use:
<vec3> closestDistance(<Triangle> tri, <vec3> _pos)
#ifndef FNC_TRIANGLE_SIGNED_DISTANCE
#define FNC_TRIANGLE_SIGNED_DISTANCE
float signedDistance(Triangle _tri, vec3 _triNormal, vec3 _p) {
vec3 nearest = closestPoint(_tri, _triNormal, _p);
vec3 delta = _p - nearest;
float distance = length(delta);
distance *= sign( dot(delta/distance, _triNormal) );
return distance;
}
float signedDistance(Triangle _tri, vec3 _p) { return signedDistance(_tri, normal(_tri), _p); }
#endif
Dependencies:
lygia
/geometry
/triangle
/triangle
.glsl
lygia
/geometry
/triangle
/normal
.glsl
lygia
/geometry
/triangle
/closestPoint
.glsl
Use:
<float3> closestDistance(<Triangle> tri, <float3> _pos)
#ifndef FNC_TRIANGLE_SIGNED_DISTANCE
#define FNC_TRIANGLE_SIGNED_DISTANCE
float signedDistance(Triangle _tri, float3 _triNormal, float3 _p) {
float3 nearest = closestPoint(_tri, _triNormal, _p);
float3 delta = _p - nearest;
float distance = length(delta);
distance *= sign( dot(delta/distance, _triNormal) );
return distance;
}
float signedDistance(Triangle _tri, float3 _p) { return signedDistance(_tri, normal(_tri), _p); }
#endif
Dependencies:
lygia
/geometry
/triangle
/triangle
.glsl
lygia
/geometry
/triangle
/normal
.glsl
lygia
/geometry
/triangle
/closestPoint
.glsl
lygia
/math
/length
.glsl
lygia
/math
/sign
.glsl
lygia
/math
/operations
.glsl
Use:
<float3> closestDistance(<Triangle> tri, <float3> _pos)
#ifndef FNC_TRIANGLE_SIGNED_DISTANCE
#define FNC_TRIANGLE_SIGNED_DISTANCE
inline __host__ __device__ float signedDistance(const Triangle& _tri, const float3& _triNormal, const float3& _p) {
float3 nearest = closestPoint(_tri, _triNormal, _p);
float3 delta = _p - nearest;
float distance = length(delta);
distance *= sign( dot(delta/distance, _triNormal) );
return distance;
}
inline __host__ __device__ float signedDistance(const Triangle& _tri, const float3& _p) { return signedDistance(_tri, normal(_tri), _p); }
#endif
LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.
Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).
It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository