POV-Ray : Newsgroups : povray.general : Minimum Distance Function : Re: Minimum Distance Function Server Time15 Aug 2022 09:51:07 EDT (-0400)
 Re: Minimum Distance Function
 From: William F Pokorny Date: 12 Jul 2022 06:10:16 Message: <62cd4888\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#62cd4888%241%40news.povray.org",
"dateCreated": "2022-07-12T10:10:16+00:00",
"datePublished": "2022-07-12T10:10:16+00:00",
"author": {
"@type": "Person",
"name": "William F Pokorny"
}
}
On 7/11/22 17:25, jceddy wrote:
>> What if instead of re-transforming the mesh data, you transform the reference
>> point to measure the length?
>> Then it's only ever one transform in either direction.
>>
> That is exactly what I tried, if I am understanding you.
>
> I want to find the distance from point P to mesh M (which contains
> vertex/triangle data as well as a transformation).
>
> So I tried basically this:
>
>
> P_inv = InverseTransformPoint(P, M->Trans)
> N = NearestPoint(P_inv, M->Data)
> V = N - P_inv  // get the vector from P_inv to N
> V_trans = TransformDirection(V, M->Trans)
>
> If(Inside(P, M))
>    distance = -Length(V_trans)
> Else
>    distance = Length(V_trans)

FYI. A chance the following inside_vector issue in play.

"Leaving mesh inside_vector untouched on transforms."
https://github.com/POV-Ray/povray/pull/361

IIRC this closed / not merged pull was last Christoph's version over my
original suggested fix on the developer mailing list. For reasons
unknown to me it never got merged into the official code base. I got
tired of re-basing branches on code updates and eventually closed it.

There is too - and also still - the issue that our documentation
suggests an axis aligned inside vector. This an unfortunate suggestion
given things like buildings are often axis aligned and any time the
inside vector is very close to perpendicular to a face's normal, the
mesh inside test becomes noisy.

Bill P.
```