Message Boards Message Boards

How to make locators as dynamic vertices of a polygon

Hello. I am trying to make an interface for 'polygon refinenment'. My starting point is this from the Locator documentation:

DynamicModule[{p = {0.5, 0.5}}, {Graphics[Locator[Dynamic[p]], 
   PlotRange -> 2], Dynamic[p]}]

Here is an example polygon

poly1 = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};

My first thought is

DynamicModule[{p1 = poly1}, {Graphics[Map[Locator,Dynamic[p1]]], Dynamic[p1]}]

But this fails with the message "Coordinate {{0, 0}, {1, 0}, {1, 1}, {0, 1}} should be a pair of numbers, or a Scaled or Offset form." If I get rid of the Dynamic, there is no error.

DynamicModule[{p1 = poly1}, {Graphics[Map[Locator, p1], 
   PlotRange -> 2], Dynamic[p1]}]

and I get four locators that I can move, but of course p1 is now not updated.

Can anyone see how to make a set of locators that update p1? I am wondering if I will have to programmatically create a list of named vertices, and make them all individually Dynamic.

Gareth

POSTED BY: Gareth Russell

Have you seen examples here for LocatorPane?

http://reference.wolfram.com/language/ref/LocatorPane.html

Perhaps something like this?

DynamicModule[{pts=RandomReal[1,{7,2}]},
LocatorPane[Dynamic[pts],Graphics[Dynamic@Polygon[pts]]]]
POSTED BY: Kapio Letto
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract