I need your help! Creating Ellipse using Fusion + Python

dinocoglitore
Advocate

I need your help! Creating Ellipse using Fusion + Python

dinocoglitore
Advocate
Advocate

Hello Fusion Community!

 

I started using Fusion not too long ago and inspired by its capabilities. I recently worked on a project to create an Ellipses panel using Fusion with Python script, and have written about it on the AutodeskHelp blog

 

I had used the Fusion User Interface to create the ellipse, but encountered some issues. 

I had a lot of fun designing and creating the ellipses, and would really appreciate any comments or feedback about the process and outcome.

 

Please go to the link below to read the Step-by-Step process that I took to achieve the ellipse. I would really appreciate your feedback and thoughts about using Python scripting with Fusion to accomplish these types of design.  
http://autode.sk/2iUannJ

 

I look forward to getting the conversation started on this!
Dino

Ellipses-Fusion 360-Python-Header-2-440x220.png

 

1 Like
Reply
1,009 Views
8 Replies
Replies (8)

Anonymous
Not applicable

Hey Dino,

 

I really like your idea as well as the pattern which emerges! It's nice to see what one can achieve with Fusion 360 using the API. I think the idea to find the ellipse using the geometric methods you describe is the way to go. If to try to find the tangent point numerically, it seems quite a fuzz to do so due to the nonlinear equations which arise. I think the program -as you describe it- looks very nice. 

Personally, I would implement the geometric search using a nested interval algorithm for the values of the major and minor axes rather than using a linear increment, as you seem to do it. This has the advantage that it's rate of convergence is exponential regardlessly of the shape and the size of the ellipse. This point, however, seems only important if you want your plugIn to be rather robust for all kinds of inputs.

0 Likes

dinocoglitore
Advocate
Advocate

Hi MaxJeblick,

I thank you very much for you comment and for your Kudo.

The Fusion API are a really interesting instrument. You can do a lot of things.

 

It was not easy for me to enter in its philosopy even because I have no 3D modelling knowledge. The articles I wrote are the first approach to different issues and I used only my fantasy to solve them.

 

I accept your suggestion to review the search algorithm. If you want to post some code I will try to better understand what are you saying.

 

Many thanks

Dino

 

0 Likes

Anonymous
Not applicable
Hi, Dino,
 
Ok, let me give you an example: Suppose one wants to determine the square root of 2 numerically. You start with x=0 and increment at each step x by 0.1 until x**2>2. The last value of x is then the numerical value of sqrt(2). In our case, it would be x=1.5, since 1.4**2=1.96<2 and 1.5**2=2.25>2. The accuracy of the answer is 0.1, since the real value of sqrt(2) is known to be found between 1.4 and 1.5. 
If one applies linear search for large numbers (let’s say one wants to find the square root of 20000 (which is approx. 141)), the algorithm is kind of slow (starting with x=0 and incrementing by 0.1).  If one increments by a larger value (let’s say 10), the answer will be less precise. 
A simple way to improve this algorithm is to start with a large increment (let’s say 10) until you find a value x such that x**2> 20000. In our case it would be x=150. Then, one knows that the value before x=150, that is x=140, fulfills 140**2< 20000. One can then start with this new value x=140, but with a smaller increment (let’s say 1). Repeating this procedure, one can find the desired square root with any precision desired. Note that this algorithm is more suitable for sufficiently small numbers.
 
Another algorithm is to use nested intervals. Again, we want to determine sqrt(2).
The idea is to start with two values, x_lower and x_higher, such that x_lower**2<2 and x_higher**2>2. Let’s take x_lower=0 and x_higher=2 (we know that 2**2>2). Then take the arithmetic mean x_m=0.5*(x_lower+x_higher)=1 and calculate x_m**2=1<2. Since x_m is smaller than sqrt(2), we replace x_lower->x_m and start over again. Then, x_m=0.5*(x_lower+x_higher)=0.5*(1+2)=1.5 and x_m**2=1.5**2=2.25>2.  Since x_m is greater than sqrt(2), we replace x_higher ->x_m and start over again. You may stop this algorithm if the value of x_m is not changing any longer, up to a certain precision. For sqrt(20000), you can take x_lower=0 and x_higher= 20000 as starting points.
The advantage of this algorithm is that it converges very fast (exponentially), regardless of the number you want to determine. Furthermore, you have control over the error of your approximation.
 
Regarding your program, I think you can take another ellipse initially, which is known not to intersect EL1 and then take the arithmetic mean of the axis of the inner and outer ellipse. By this, one could implement the nested interval algorithm.
By this method, it doesn’t matter if your ellipse EL1 is very large or very small in the beginning. 
 
Best,
Max
0 Likes

dinocoglitore
Advocate
Advocate

Hi Max,

Your explanation of the algorithm is very clear and I agree with you that your suggestion is right for the issue that I posted.  I used the first part of your post because was the most simple and the first that came to my mind. My first goal was not to get the efficiency of the script, but simply to solve the issue. As you can see I use Fusion to create modesl that are someway in my mind. They have nothing of productive and I do that just as an instrument to learn more and more the Api.

I thank you a lot for your contribution and I will try to implement your algorithm into the script just to verify thet you are right.

 

Best, Dino

0 Likes

Finbat
Explorer
Explorer

Hi Dino

 

I have done Lame curves before e.g. x³ + y³ = r³ and used a segmented approach (effectively calculating points).

 

For ellipses I would go back to how they used to be done on a drawing board (no I am also struggling to remember how I did it). Googling "n arc ellipse approximation" I got a sensible algorithm with pseodocode "https://www.geometrictools.com/Documentation/ApproximateEllipse.pdf" I would suggest this may be the way to go.

 

Regards

 

Finbat

Grunt Programmer

0 Likes

dinocoglitore
Advocate
Advocate

Hi Finbat, thank you for your reply.

When I began to study for the article I posted, I remember that I found the link that you point out. I did not use it because in this document there is the function Circumscribe(…). But there is no suggestion of how it is implemented.

To draw the ellipse I use the SketchEllipse object of the Fusion API.

If you have more information about that document I will happy to listen to you.

 

However if you have some issue to approximate an ellipse, during my study, I found another article that I can suggest to you: http://www.diem.ing.unibo.it/personale/liverani/papers/9_.pdf

It is in Italian but there is an explicit algorithm defined with a Flow Diagram that can be easily understood.

If you need help in the translation I will try to give you a hand.

Many Thanks.

Dino

1 Like

Finbat
Explorer
Explorer

Hi Dino

 

I am pretty sure "Circumscribe" means "Draw Arc"

 

Regards

 

Fin

0 Likes

dinocoglitore
Advocate
Advocate

Hi Fin, thanks for the answer. Now it is more clear. It can be useful for another project that I have in mind.

Thank you

Dino

0 Likes