-5

What's the most compact WL translation of this GLSL expression:

length(max(vec2(x,y),s))

?

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
ChrisJJ
  • 608
  • 3
  • 8
  • What does it do? What are x, y, s? – Michael E2 Jan 13 '18 at 02:00
  • If you have to ask, you won't know the answer. If you want to find out, learn GLSL. – ChrisJJ Jan 13 '18 at 17:31
  • 4
    @ChrisJJ It is not how it works, this site is about Wolfram Mathematica, everything that does not concern it should be explained in the question, making it clear and useful for future visitors. – Kuba Jan 13 '18 at 17:33
  • 2
    Additionaly, I don't understand your repost, don't existing answers solve the problem? – Kuba Jan 13 '18 at 17:34

1 Answers1

2
Norm[s + Ramp[{x, y} - s]]

Sqrt[Abs[s + Ramp[-s + x]]^2 + Abs[s + Ramp[-s + y]]^2]

ClearAll[x, y, s]
Reduce[s + Ramp[{x,y} - s] == {Max[x, s], Max[y, s]}, {x, y, s}, Reals]

True

Manipulate[Row[{Plot3D[Norm[s + Ramp[{x, y} - s]], {x, -1, 1}, {y, -1, 1}, 
    ImageSize -> 400, Exclusions -> None], 
  Plot3D[Norm[Max[#, s] & /@ {x, y}], {x, -1, 1}, {y, -1, 1}, ImageSize -> 400]}], 
 {s, 0, 1}]

enter image description here

Or

Norm[s + ({x,y} - s) UnitStep[{x,y} -s]]

Sqrt[Abs[s + (-s + x) UnitStep[-s + x]]^2 + Abs[s + (-s + y) UnitStep[-s + y]]^2]

Reduce[s + ({x,y}-s) UnitStep[{x, y} - s] == {Max[x, s], Max[y, s]}, {x,y, s}, Reals]

True

kglr
  • 394,356
  • 18
  • 477
  • 896