Message Boards Message Boards

[✓] Locator constrained by polygon and NSolve


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

POSTED BY: Andras Gilicz
1 year 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],
     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
1 year ago

Dear Gianluca,

Works beautifully, exactly as I wanted :-)

Tx very much, best regards Andras

POSTED BY: Andras Gilicz
1 year ago

Group Abstract Group Abstract