MoI discussion forum
MoI discussion forum

Full Version: Elastica script

Show messages:  0-19  20-26

From: bemfarmer
30 Oct 2014   [#1]
The elastica script generates seven of the nine classes of elastica curves, creating a range of 2d curves.
The other two classes are the circle and the line.
(A half near circle, and a near line are generated for extremely high or low shape values.)

The curves are "half" curves. The second "half" of the curve can easily be mirrored.
For shape values greater that -1, an additional bottom portion can be done by rotation, or by mirror and move.
For shape values less than or equal to -1, another curve can be added on by mirror.

The curves are related to pendulum motion. For Shape = 0, the "Mylar Balloon" curve results, rotated 90 degrees.
The aspect ratio is correct, 0.599+...

The paper gives Shape values for the seven cases of 0.5, 0, -0.4, -0.65223, -0.9, -1, and -1.2.

A general link to the source paper is:
http://www.emis.ams.org/proceedings/Varna/vol9/Djondjorov.pdf

The curves may be further processed by MoI. Rebuild is suggested after a longer curve is formed.
Sweep can be done. Have not tried flow or twist yet.

- Brian




If it stops raining, or the new telephone wires are installed, internet access may work well again.

I may try the techniques of Gear, with a mirror.

Attachments:
SevenElasticTypes01.3dm
_Elastica.zip
_Elastica2.zip

Image Attachments:
SevenElastica.PNG 


From: TpwUK
31 Oct 2014   [#2] In reply to [#1]
Cool - I had to do these way back in my infancy school days when i was learning to read n write !

Martin Spencer-Ford
From: bemfarmer
31 Oct 2014   [#3] In reply to [#2]
Thank you Martin

Attachments:
ElasticaTest05.3dm


From: Frenchy Pilou (PILOU)
1 Nov 2014   [#4]
Original!
From: bemfarmer
5 Nov 2014   [#5] In reply to [#4]
Thank you PILOU.

Post #1 now includes _Elastic2 script, which makes the same curves as _Elastica, but Mirror, Join, Concatenate and Rotate are used
to build a complete unit curve, (or two in some cases).
The curve is fast and smooth as it uses the techniques of Max Smirnov's Gear script, a programming somewhat unconventional from
the more "traditional" Moi scripts. I left in the extrude.
The timing loop generated Keypad entry problems with "." and "-", which Michael solved.
Please report any problems. I would suggest backing up any work before using the script, just in case...

Brian.

I used flow to make some circular loops.
From: bemfarmer
29 Nov 2014   [#6]
I've go a new script working well with the "standard" .js and .htm method, but it is very slow.

While trying the Gear type of scripting, using an alert message function in the .htm file is giving
"Range error maximum call stack size exceeded" message.

I guess it is from the ongoing timing loop...

The faster "Gear" method is not working yet, so I'm going to switch to the "older" .htm speedup method.

- Brian


Image Attachments:
RangeErrorStackSizeExceeded.PNG 


From: Michael Gibson
29 Nov 2014   [#7] In reply to [#6]
Hi Brian, change that to instead be:

code:
    function alert( msg )
    {
        moi.ui.alert( msg );
    }


The one you have there right now has moi.ui.commandUI.alert() - commandUI is a way for a script to access the global object of the loaded .htm file, and doing commandUI.alert() means it is looking for a function alert() in that .htm file which is the very same function so it's calling itself over and over again in a recursive loop.

- Michael
From: bemfarmer
29 Nov 2014   [#8] In reply to [#7]
Thank you Michael

Alert is working.

(Now to get the bugs out of my script...)

- Brian
From: bemfarmer
21 Jul 2022   [#9] In reply to [#1]
The Elastica2 script has some sort of Bug. (MoI5beta)
Selection of points in 3D View can result in curves in two different planes.
Something to do with cplane and Frames, or cplane z points, I guess.
It is an 8 year old script. Back when much script was placed in .htm file, for speed. (No longer necessary.)
The script seems to work fine in Top, Front and Right views.

When using the following code in 3D view:
var cplane = pointpicker.ptframe;
what orientation is used for cplane?

Still studying...
Will try it in MoI4 tonight...

- Brian

It is probably NOT a MoI bug (?)
From: Michael Gibson
21 Jul 2022   [#10] In reply to [#9]
Hi Brian,

re:
> When using the following code in 3D view:
> var cplane = pointpicker.ptframe;
> what orientation is used for cplane?

It should be the same as Top view. Unless you have set a custom cplane using View > CPlane.

- Michael
From: bemfarmer
25 Jul 2022   [#11]
The Elastica2 script works well in 3D, Top, Front, and Right views, when the selected point has the 3rd coordinate = 0. (z=0 in Top View, or 3D View)
In 3D View, when z is non-zero, the first Mirror is OK. The second Mirror (and Rotate?), go off at strange angles.

The first quarter of the final curve is created with a cplane, from multiple x and y, with z = 0, points, then evaluated to world coordinates.

The first mirror of the curve seems to work fine, because it uses the same cplane:
code:
 var mirror1 = factory( 'mirror', curve, cplane, cplane.evaluate( 0.0, 1.0, 0.0 ) );


The problem is that the second Mirror is using World coordinates, instead of cplane coordinates.

It is confusing...

I need to create cplane2, located at end point, given in World coordinates, of the first quarter curve, in the current View, the same View as the original cplane, in order to do mirror2 and rotate...
But the view could be in any of the 4 views.

Michaels recent post of code:
moi.view.setCPlane( Frame, ApplyToAllViews, OrientOrthoViews ); - takes a required coordinate frame parameter, optional boolean parameter for whether to apply to all views or 3d view only, and optional boolean parameter for whether to orient ortho views or keep them in world.

- Brian
From: bemfarmer
26 Jul 2022   [#12] In reply to [#11]
I do have endPt of the initial quarter curve, in cplane coordinates, (raw_x, raw_y, z=0).
Need to create cplane2 from these.

[Note: The point (raw_x, raw_y, z=0), in Front and Right Views, would represent (Y2,Z2,X2) and (X3,Z3,Y3), respectively.


I think that I did cplane2 = Frame2, back in 2013:
code:
var FrameOrigin = ptRaw;//ptRaw is the last point of the "half" curve
	var x2 = raw_x + 1.0; // raw_z=0
	var FrameXAxis = cplane.evaluate( x2, raw_y, raw_z );
	var y2 = raw_y + 1.0;
	var FrameYAxis = cplane.evaluate( raw_x, y2, raw_z );				
	var Frame2 = moi.vectorMath.createFrame( FrameOrigin, FrameXAxis, FrameYAxis );


Maybe need to get rid of cplane.evaluate above...?
But qtr curve is in World coordinates...Need Frame2 in World coordinates for Mirror2 and rotate...

I hope some of this makes sense. It is confusing to me.
Will try again tonight...

- Brian

cplane and Frame are related, but are not the same thing?
cplane converts World coordinates to local coordinates? Or vice versa...? evaluate...
code:
//Convert to cplane frame.
	var base_x = cplane.distancex( BasePt );
	var base_y = cplane.distancey( BasePt );


Frame provides orientations for commands like Mirror and Rotate?

From: Michael Gibson 10 May 2013 (8 of 35)

5878.8 In reply to 5878.6
Hi Brian, ok so I think the problem is the script is not quite getting the correct 2D coordinates for doing your calculations.

At the start of your function buildClothoid you've got some calls to cplane.evaluate() there - but that's probably not right, you use cplane.evaluate() for converting from the frame's "local coordinates" into world coordinates.

At that point in the script for buildClothoid() you actually need the reverse I think - the points given to you by the pointpicker are in world coordinates and you want to get them into 2D coordinates within that cplane's local coordinate system before you start doing calculations with them. Then when you're done doing your calculations that's when you want to use cplane.evaluate() to convert from 2D local cplane coordinates back into world coordinates.

The .evaluate() call is only for doing the last part (2D local into 3D world conversion) - you need something different for the first part (3D world into 2D local cplane conversion).

For doing the 3D world into 2D local conversion you can get the local 2D plane coordinate from a 3D world coordinate by doing cplane.distancex() and cplane.distancey() which get the signed distance of the given 3D point from the x-axis plane and y-axis plane of the frame, something like this:

var localx = cplane.distancex( worldpt );
var localy = cplane.distancey( worldpt );

So if you use that in the start of buildClothoid() it should then give you uniform behavior in all views, here's an updated buildClothoid function that should work:
From: Matadem
26 Jul 2022   [#13]
Good day.

I get invalid function argument line 0 Error

When I try to use this script in an existing drawing.

When I start with a blank new file it works :/
From: bemfarmer
26 Jul 2022   [#14] In reply to [#13]
Hi Matadem,

Yes, there is a bug (or two?), when cplane z equivalent from pointpicker is nonzero.
I am looking into it.
It should be a script bug, not a MoI bug :-)

-Brian
From: bemfarmer
26 Jul 2022   [#15] In reply to [#14]
The line0 error shows up in MoI4 and MoI5 beta, when the figure8 elastica has been selected and the script re-ran, ( with z equivalent not zero.)
Sometimes this bug also occurs in Top View...With z = 0.
MoI3 shows a different looking similar error, in the .js file.- perhaps more useful.
MoI3 also shows the bug with mirror2 at strange angle.
- Brian
From: bemfarmer
26 Jul 2022   [#16] In reply to [#15]
I may try doing Mirror and Rotate for each View on a case by case basis.
3D, Top, Front, Right Views.

- Brian
From: bemfarmer
26 Jul 2022   [#17] In reply to [#16]
Organizing thoughts:

Notes on bug(s) in Elastica2 script.

The Elastica2 script creates 7 of the 9 elastica curves.
The circle, and the line elastica are not created by the script.
The elastica curve created is based upon the Shape parameter, U.value.
The Shape slider ranges from -2 to 0.99999.
A circle would need a U.value of -infinity,
and a line would need a U.value of 1.0. But max U.value is set to 0.99999.

Based upon the Shape parameter, U.value, the
script mathematics culminates in an initial curve, with final point:
var pt = cplane.evaluate( x, y, z ); in world coordinates.
Except for the (half) curve created by U.value of -1.0, the initial curve
is one quarter of the final elastica curve.
The U.value of -0.65223... creates a "figure 8" final elastica curve.

The initial quarter curve can be created in any one of the 7 MoI views,
3D, Top, Bottom, Front, Back, Right, Left.
Using two mirrors, and/or rotation, the initial curve becomes 4 curves, which are joined to become one final elastica curve.

One bug results in an error message, re: Frames in MoI3, for some point selections at some U.values. (Especially for a point with 2 equal
coordinate values.) (Does not always happen. Might be a cleanup problem?)
The second bug has half of the final curve at strange angles, mostly for
points with non-zero third coordinate value. (Occasionally for third coordinate of zero. The strange angles are not the same for different
positions of the initial picked point.

The 3D view has characteristics like a Top View.
Top, Front, and Right views have different x, y, and z axis pairs,
So World coordinate Frames for mirror1 and mirror2, and rotate will be set up for each View Case.
Using Cases should eliminate the bugs.
Another goal is to revert most of the javascript code to the .js file, from the .htm file. (An old Max technique.)
Beginning with MoI4, the .js file is as fast as placing script in the .htm file.

mirror1 Frame is done with base point at the initial picked point.
mirror2 Frame is done with base point at the quarter curve end point.
rotate Frame is done with base point at the initial picked point.
join is also done.

- Brian
From: bemfarmer
27 Jul 2022   [#18] In reply to [#17]
This has been partly mentioned above.

Let "a" be a number representing a coordinate.

The _Elastica2 script displays an error message, in all 4 views, for a center point with ( x, y, z ) coordinates ( a, -a, 0 ) or ( -a, a, 0 ).

The error message in MoI3 shows a line in the Script section of the _Elastica2.htm file:
code:
var Frame = moi.vectorMath.createFrame( FrameOrigin, FrameXAxis, FrameYAxis );


The error message in MoI4, or MoI5beta, is the previously posted:
Script error
Invalid function argument
line 0
OK button.

- Brian
For nonzero z, coordinates ( a, -a, z ) or ( -a, a, z ) creates a curve, but with the strange angle mirror2 bug.

Will try some different code tonight or tomorrow, with better understanding of cplanes and Frames.
From: Michael Gibson
27 Jul 2022   [#19] In reply to [#18]
Hi Brian,

re exception here:
code:
var Frame = moi.vectorMath.createFrame( FrameOrigin, FrameXAxis, FrameYAxis );

In order to form a coordinate system the given xaxis and yaxis can't be parallel to one another.

Ideally they should be at a 90 degree angle to each other so they directly form an orthonormal frame. But it will tolerate if they are not 90 degrees to each other but they can't be parallel because they need to have a z axis direction formed by the cross product between them.

So if the angle between them is less than 2 degrees it will throw an "Invalid argument" exception.

- Michael
From: bemfarmer
27 Jul 2022   [#20] In reply to [#19]
Thank you Michael.

Your help, and Cross product information makes sense.

I'll be doing some corrections to the elastica2 script over the next few days, as work and energy level allows :-)

- Brian

Show messages:  0-19  20-26