# Define a 3D surface for input in Region function

I am looking for the shortest distance from a 3D surface to a random point, and also for the exact point on the surface.

These are the definitions and visualization.

func[t1_, L1_, t2_, L2_] := (L1 t1 + L2 t2)/(L1 + L2) - 3
plotFunc := ContourPlot3D[func[t1, L1, 2.9, L2] == 0, {t1, 0, 10}, {L1, 0, 10^2}, {L2, 0, 10^4}]
coordinate := {RandomReal[{1, 10}], RandomReal[{1, 10^2}], RandomReal[{1, 10^4}]}
Show[plotFunc, Graphics3D[{PointSize[Large], Point[coordinate]}]]


In this answer https://mathematica.stackexchange.com/a/48567/52207 is described how to use RegionDistance and RegionNearest, which is exactly what I need.

I cannot work out how to define the 3D surface such that it can be used in the Region function like in the above link.

Use ImplicitRegion to create the region:

func[t1_,L1_,t2_,L2_] := (L1 t1+L2 t2)/(L1+L2)-3
plotFunc := ContourPlot3D[func[t1,L1,2.9,L2]==0,{t1,0,10},{L1,0,10^2},{L2,0,10^4}]
region = ImplicitRegion[func[t1,L1,2.9,L2]==0,{{t1,0,10},{L1,0,10^2},{L2,0,10^4}}];
rn = RegionNearest[region];
rd = RegionDistance[region];


Then, you can use rn and rd as needed, for example:

SeedRandom[100]
coordinate = {RandomReal[{1,10}],RandomReal[{1,10^2}],RandomReal[{1,10^4}]}
rn[coordinate]
rd[coordinate]
Show[
plotFunc,
Graphics3D[{PointSize[Large], Red, Point[coordinate], Green, Point[rn[coordinate]]}]
]


{1.11583, 34.5268, 2232.92}

{9.21508, 35.9272, 2232.9}

8.21944

• Thank you for your help. Precisely what I was looking for! – Thomas Rademaker Sep 13 '17 at 19:52