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:

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

{1.11583, 34.5268, 2232.92}

{9.21508, 35.9272, 2232.9}


enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.