MoI discussion forum
MoI discussion forum

Full Version: Offset + Rebuild as polyline interactively

From: archetype (FABIENF)
22 Sep 2018   [#1]
Hi all,

I was wondering if it's feasible to combine the functionality of offset curve (through point) with curve reduction to a polygon with a specified polygon count (preferably, with a slider or +/- keyboard adjustment). Is this something that can be done using a script?

Basically, it would take the output from offset curve through point and apply the ReconstructCurve.js script in polyline mode, without 'dropping' the tool first, allowing interactive adjustment of said parameters until satisfied.

I'd like to approximate a contour using a polygonal shape, while keeping a certain margin from the original curve.

Lastly, it would be helpful if the polygon produced would remove any intermediate points below a specified angle threshold (another slider, or shift+/shift- keys), effectively turning those segments into a straight line without superflous points.

While I am familiar with scripting, I am not sure how to create such an interactive tool.

- Fabien
From: Michael Gibson
22 Sep 2018   [#2] In reply to [#1]
Hi Fabien, I think it would be possible to do that but interactive tools can tend to take a lot of work to make. It would probably help if you could give more definite details about it like exactly what controls you want on each step of the command. For sliders for example what would be the range of the slider?

Right now from your description it's difficult to help you without a more detailed spec.

- Michael
From: archetype (FABIENF)
22 Sep 2018   [#3] In reply to [#2]
Hi Michael,

Do you think the current Offset command/tool can be extended with such functionality? I mean as a customized version of the current command, perhaps. Or a duplicate with said behavior.

In that case, the steps would be as follows:

1. pick a curve
2. choose offset tool, through point option (perhaps it doesn't preclude the fixed distance option, allowing both modes of offset?)
3. in the sidepanel/tool options, there would be a slider ranging from 3 to 32 points (with numeric input for any 3+ point value, to exceed 32?)
4. all the time, the offset through point picker is still active, and the number of points remains adjustable until a point is placed
5. the factory is committed into the final polygonal curve and the tool dismissed

At stage 3, in addition (or even instead of) the slider, the +/- keys could be pressed.

Finally, if the curve reconstruction algorithm could eliminate any excess points (by angle threshold), that would be a bonus. UI-wise, a slider from 0 - 30 degrees would be great (I suspect 30 degrees is a fair maximum for this).

UI-wise, I think I'd manage most of it on my own, as long as I have some (initially hard-coded) parameters to feed into the script that provides the offset + reconstruction step. I'd likely be able to figure out the keyboard interaction (+/-) on my own, too, if that helps to lighten the work needed.

Thanks for your consideration.

- Fabien
From: Michael Gibson
23 Sep 2018   [#4] In reply to [#3]
Hi Fabien, the regular Offset command binds UI controls directly to the offset factory. In your case since you want to do something other than just generate an offset that won't work for your case. So I'm not really sure about modifying the existing command for what you want.

I've attached a command written from scratch that I think does the basics of what you are describing, I hope it is a good starting point for you. Probably requires MoI v4.

- Michael

Attachments:
OffsetRebuild.htm
OffsetRebuild.js


From: archetype (FABIENF)
23 Sep 2018   [#5] In reply to [#4]
Wow, thanks Michael! This will be very helpful! I've noticed that closed curves yield an open polyline right now - I haven't looked into closing it in the script yet, but I thought I'd mention it.

I take it that only the offset of the point is taken into account, not its relative position along the curve? In a perfect world, it would be also one of the points of the polyline generated ;)

Further simplification of the polyline based on a threshold angle is probably a lot more involved, too, I guess.

Thanks again for your help!

- Fabien
From: Michael Gibson
23 Sep 2018   [#6] In reply to [#5]
Hi Fabien, you're welcome!

> I've noticed that closed curves yield an open polyline right now - I haven't looked into
> closing it in the script yet, but I thought I'd mention it.

For that try looking at the .isClosed property on the curve and if true insert the start point at the end of the polyline inputs.


> I take it that only the offset of the point is taken into account, not its relative position along the
> curve? In a perfect world, it would be also one of the points of the polyline generated ;)

Sorry I'm not understanding this part. Which point are you referring to here?


> Further simplification of the polyline based on a threshold angle is probably a lot
> more involved, too, I guess.

Yes, kind of more involved but it should be doable if you want to try it. You would need to make some vectors between the points, use dotproduct to determine the cosine of the angle between them and figure out the logic for remaking the points skipping some I guess.

- Michael
From: archetype (FABIENF)
24 Sep 2018   [#7] In reply to [#6]
Hi Michael,

I'll add the closed curved functionality and post back the script here, thanks.

Regarding the point on polyline behavior, what I meant is that the picker does not let you place an actual point to be used as the starting point as well as the offset value. Currently, only the offset value is read, not the location of the point where it was clicked. If that would be possible, one could 'slide' along the original curve, and determine the place where the points are being distributed from. I'm not sure if that complicates things a lot, though.

I'll see if I can do some polygon reduction work as well ... thank you for the hints.

- Fabien
From: Michael Gibson
24 Sep 2018   [#8] In reply to [#7]
Hi Fabien,

> If that would be possible, one could 'slide' along the original curve, and determine the place
> where the points are being distributed from. I'm not sure if that complicates things a lot, though.

It sounds like that would need a totally different point distribution strategy. Right now it just makes evenly spaced points along the offset. From what you are describing here I'm not sure how that would work if for example your new point was close by the start point of an open curve. Would you want the start point of the curve to be ignored and not included in the polyline?

- Michael