Message Boards Message Boards

[✓] Locator constrained by polygon and NSolve

GROUPS:
mathematics dynamic interactivity equation solving graphics and visualization wolfram language numerical computation

Dear Community,

I have a polygon with a constrained locator in it. I would like to draw a horizontal line from the locator towards the left boundary of the polygon, which is also given by a stewise function called qgHSZ. I try to achieve this with NSolve, but I get some strange warnings, like

"Part 2 of {0.5,10.} does not exist" Why?? "NSolve was unable to solve the system with inexact coeficients, etc." Not clear either. If I test NSolve below the plot, it works fine.

What do I do wrong? Notebook attached. Tx for the kind help in advance, regards, Andras

Attachments:
POSTED BY: Andras Gilicz
Answer
6 days ago

This seems to work:

DynamicModule[{pt = {0.5, qgHSZ[.2]}, from = .2, x},
 {Graphics[{Dynamic[Line[{{from , pt[[2]]}, pt}]],
    LightBlue, Opacity[0.9], Polygon[pts],
    Locator[
     Dynamic[pt , (pt = RegionNearest[Polygon[pts], #]; 
        from =  x /. NSolve[ qgHSZ[x] == pt[[2]], x][[1]]) &]]},
   Axes -> True, AspectRatio -> 1], Dynamic[pt]}]
POSTED BY: Gianluca Gorni
Answer
5 days ago

Dear Gianluca,

Works beautifully, exactly as I wanted :-)

Tx very much, best regards Andras

POSTED BY: Andras Gilicz
Answer
5 days ago

Group Abstract Group Abstract