1
$\begingroup$

I need to find the shortest distance between the two regions and the two points of the shortest distance, but the following code cannot achieve this requirement:

reg1 = ImplicitRegion[
  x^2 + y^2 - 2 z^2 == 0 && x + y + 3 z == 5, {x, y, z}]
reg2 = ImplicitRegion[z == 0, {x, y, z}]
RegionNearest[reg1, reg2]

What can I do to find the shortest distance between two regions?

$\endgroup$
1
  • 2
    $\begingroup$ Here's an idea, which does not want to finish evaluating so only as a comment: reg1df = RegionDistance@reg1; NMinimize[ reg1df[{x, y, z}], {x, y, z} \[Element] reg2] $\endgroup$
    – Kuba
    Aug 14, 2020 at 8:43

2 Answers 2

1
$\begingroup$

Lagrange multiplier method is a alternative solution which can be solve by hand.

    g = z + p (x^2 + y^2 - 2 z^2) + q (x + y + 3 z - 5);
    Solve[Grad[g, {x, y, z, p, q}] == {0, 0, 0, 0, 0}]

(* {{p -> -(1/10), q -> -1, x -> -5, y -> -5, z -> 5}, {p -> 1/10, 
  q -> -(1/5), x -> 1, y -> 1, z -> 1}} *)
$\endgroup$
1
4
$\begingroup$

This can be done as follows.

reg1=ImplicitRegion[x^2+y^2-2 z^2==0&&x+y+3 z==5,{x,y,z}];
reg2=ImplicitRegion[z==0,{x,y,z}];Minimize[{Norm[{a,b,c}-{s,t,r}],{a,b,c}\[Element]reg1&&
{s,t,r}\[Element]reg2},{a,b,c,s,t,r}]
(*{1, {a -> 1, b -> 1, c -> 1, s -> 1, t -> 1, r -> 0}}*)
$\endgroup$

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.