Hi all,
My message is also addressed to "Ronaldo" who scratched my post to reframe some aspects of my personal OpenSCAD review. "Ronaldo", you were right to do so and I thank you for it.
Of course, without experience with this software, I didn't pretend to make my code a benchmark example. I'm not an acrobat in programming and mathematics ! ...
I didn't think I would go any further than the two experiences I showed in my contact topic, but I changed my mind to see what you told me a little better.
![]()
I attach the program code. It is autonomous and consists of :
1)° - The function
"formule_Bezier_3D(
)" :
In addition to looking for the syntax to code the function, I complained about the error message given by the compiler which refused to specify the name of the matrix "mat_coef" in the result. The error disappeared by explaining it twice. ! ...
Thanks to the "let ()" instruction, I discovered the possibility of programming inside a function.
The function returns a matrix of one scalar. I failed to return the scalar instead of the matrix (syntax errors) ! ...
The approach is surprising but it fuels another language ! ... 2)° - the module "
Bezier_3D ()" :
Nothing more to say.
2)° - the body of the program :
In relation to the data, the two covers have been brought back near the origin of the axes to see them better.
Cordially.
Lou Papet _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
"Pourquoi faire simple quand on peut faire encore plus simple !..."
"Why keep it simple when you can make it even simpler ! ..." "Le plus simple est de ne pas faire.....seulement si c'est possible !..." "The easiest way is not to do ..... only if it is possible ! ..." |
Hi all, I apologize for failing to provide part of my program, the one that defines the data.
Here they are below. Regards, Lou Papet
Le jeu. 4 févr. 2021 à 10:11, Jean-Pierre Rousset <[hidden email]> a écrit :
-- "Pourquoi faire
simple quand on peut faire encore plus simple..." "Le plus simple est de ne pas faire.....seulement si c'est possible !..." _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
"Pourquoi faire simple quand on peut faire encore plus simple !..."
"Why keep it simple when you can make it even simpler ! ..." "Le plus simple est de ne pas faire.....seulement si c'est possible !..." "The easiest way is not to do ..... only if it is possible ! ..." |
In reply to this post by Lou_Papet
Em qui., 4 de fev. de 2021 às 09:12, Jean-Pierre Rousset <[hidden email]> escreveu:
Jean-Pierre, As I said before, instead of computing a Bezier point of a curve or a surface patch one coordinate at a time it is more concise, easier-to-read and faster to explore the ability of OpenSCAD to operate on vectors and matrices. With basic vector algebra calculus, the computation of Bezier stuff may be expressed by shorter expressions. Besides, I generally prefer to define more functions than modules because functions are flexible and can be used in different circumstances for instance composing it with other functions. That being said, I will give you one way that Bezier functions and modules could be defined so they are building blocks to a whole set of applications. Although I prefer to define those functions recursively for general degrees, I will express them here restricted to degree 3 as you did. For Bezier curves: function Bezier_curve_point(pc, u) = pc*[ (1-u)*(1-u)*(1-u)
, 3*u*
(1-u)*(1-u)
, 3*u*u*(1-u), u*u*u ]; module Bezier_curve(pc, n=20, width=.1) { pts = [for(i=[0:n]) Bezier_curve_point(pc, i/n) ]; for(i=[0:n-1]) { hull() { translate(pts[i]) sphere(width); translate(pts[i+1]) sphere(width); } } } In the function definition, pc should be the list of 4 "control points" where a control point may be a number, a numerical vector of any dimension, or even a matrix! The constraint here is that pc must be a uniform list in the sense that any pair of its control points is summable (therefore they should have the same dimension). That means we may use Bezier_curve_point() to 2d or 3d curves. Or even higher dimension Bezier curves. In the module definition, pc is expected to be a point in 3d (in order to have a legal translate()). The arg u should be a number (possibly in the interval [0,1]), n an integer greater than zero and width a positive number. For Bezier surface patches: function Bezier_patch_point(pc, u, v) = Bezier_curve_point( Bezier_curve_point(pc, u), v); module Bezier_patch(pc, n=20, thick=.1) { pts = [for(i=[0:n]) [for(j=[0:n]) Bezier_patch_point(pc, i/n, j/n) ] ]; for(i=[0:n-1], j=[0:n-1]) { hull() { translate(pts[i][j]) sphere( d=thick ); translate(pts[i+1][j]) sphere( d=thick ); translate(pts[i][j+1]) sphere( d=thick ); translate(pts[i+1][j+1]) sphere( d=thick ); } } } In all above, pc should be a bidimensional matrix of control points as usually is seen in text books and papers. The main point here is the definition of the function Bezier_patch_point() that explores a property of Bezier surfaces and the ability of
Bezier_curve_point() to operate with matrices as control points. About your code: Although you have expressed the computation of a point on a Bezier surface patch in a matrix form it doesn't lead to a more efficient
(or neater)
code because you still break the computations down to coordinate level. I have not had any compiler complaints by using mat_coef instead of a hard code of it. Ronaldo _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by Lou_Papet
On 2/4/2021 2:00 AM, Jean-Pierre
Rousset wrote:
Uncheck "Automatic Preview", at the top left corner of the Customizer pane. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by Ronaldo
Em qui., 4 de fev. de 2021 às 09:12, Jean-Pierre Rousset <[hidden email]> escreveu: For the coding of the functions, I searched without success for a documentation explaining all the programming tips. So So I drew informations on the web and follows me inspired by doing a lot of tests. The compilation caused me a lot of misery ! ... I forgot to give you some references. One reference for beginners is OpenSCAD Tutorial but it avoids an introduction to function. You may find a detailed introduction to OpenSCAD functions in the OpenSCAD Manual. OpenSCAD functions benefit from the list comprehension resources of the language. In the Tips&Tricks section of the Manual, you may find some ideas for simple functions and modules. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Hi,
Many thanks, Ronaldo, for indicating me to a documentation reference on OpenSCAD function coding. I temper my initial opinion because, looking at the proposed codes, I realize that OpenSCAD is not a CAD application but rather a one-pass modeler. Am I wrong ?.. Indeed, I understand that the software is first of all an interpreter which analyzes the code provided to generate the mesh of the model in the cache in order to be able to more easily manipulate it visually on the screen and, possibly, to cut it into slices. to produce an STL file for 3D printing. With each submission, the program regenerates the components that change and it should be the same for the animations. Therefore, I think I understand a little better why OpenSCAD does not understand the instruction "i = i + 1" and refuses that we reassign a variable.
Originally, was the code not entered directly on the keyboard ? ... This would explain the concern to adjust the "language" for a better contraction of operations and thus reduce the burden of manual input. I will probably surprise you by admitting that, although I understand the usefulness of it for this last reason, I am not a big friend of this kind of coding. I know that it is very promising for many people, in order to show the intellectual subtlety and the mastery of I do not know what theoretical concept. For a lot of people, understanding the code isn't as instantatly as you might think. It takes some learning to be familiar with it. In OpenSCAD, it is rather the syntax of the instructions that bothered me the most because there, you have to strictly follow the rules, otherwise the program don't make the job.
I suppose that talking about a compiler implies that there was machine code if it is real or pseudo-machine code if it is a super shell --- not at all a virtual machine as claimed by thes Java'developers ---.
In this case, a compiler analyzes the two forms of writing, condensed and non-condensed, which does the work for it, to produce mostly the same sequence of assembler-instructions. Experiment yourself by setting yourself as basic machine instructions on registers/index and memory, the "load", the "store", the "add", the "mult", the "div", the "branch" and "branch on condition" ! ... At Christmas 2019; I offered a "Creatily3D Ender 3" 3D printer to my grandson, the half with my daughter. So I was able to carry out myself some small experiments in particular the study of the "epicyclic train" based on herringbone gears which works very well. ![]() Only, after many tests, my enthusiasm was quickly limited by the quality of the result. I recognize that the printer which was not given (!) is for the general public therefore low-end ! ... I must also modestly say, that after the age of 80, I do not much need such a machine. Best regards, Lou Papet Le ven. 5 févr. 2021 à 00:48, Ronaldo Persiano <[hidden email]> a écrit :
-- "Pourquoi faire
simple quand on peut faire encore plus simple..." "Le plus simple est de ne pas faire.....seulement si c'est possible !..." _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
"Pourquoi faire simple quand on peut faire encore plus simple !..."
"Why keep it simple when you can make it even simpler ! ..." "Le plus simple est de ne pas faire.....seulement si c'est possible !..." "The easiest way is not to do ..... only if it is possible ! ..." |
Free forum by Nabble | Edit this page |