POV-Ray : Newsgroups : povray.general : Minimum Distance Function : Re: Minimum Distance Function Server Time15 Aug 2022 10:06:42 EDT (-0400)
 Re: Minimum Distance Function
 From: jceddy Date: 11 Jul 2022 17:30:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.62cc95526fb4e448864166f75d51d79c%40news.povray.org",
"dateCreated": "2022-07-11T21:30:00+00:00",
"datePublished": "2022-07-11T21:30:00+00:00",
"author": {
"@type": "Person",
"name": "jceddy"
}
}
> 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)

....and the result was much worse than finding the distance from point P to mesh
M (which contains transformed vertex/triangle data), but doing this:

N = NearestPoint(P, TransformAllVertices(M->Data, M->Trans))
V = N - P

If(Inside(P, M))
distance = -Length(V)
Else
distance = Length(V)

I mean, obviously the second one looks cleaner, as well, but it hides all the
code required to make sure M->TransformedData is there to use.
```