## How to approximate a surface that was cut using a condition function

Questions and answers regarding MathMod scripts basics
dayonghu1978
Posts: 10
Joined: Thu Dec 26, 2019 7:27 pm

### How to use the function "if" and "max"

In the case of Schwarz Cylinder, the script is as follows:
{
"Iso3D": {
"Component": [
"Schwarz Cylinder"
],
"Const": [
"N=8"
],
"Description": [
"Schwarz Cylinder by Abderrahman Taha 05/12/2015"
],
"Funct": [
"Schwarz=cos(x) + cos(y) + cos(z)",
"isoCondition_0=(x^2-3.2^2)",
"isoCondition_1=(x^2-2.6^2)",
"isoTransform=if(isoCondition_0(x,y,z,t)<(0),-Schwarz(x,y,z,t),1)+exp(isoCondition_1(x,y,z,t))",
"isoTransform2=isoTransform((sqrt(x*x+z*z)-12),y,N*atan2(z,x),t)"
],
"Fxyz": [
"-isoTransform2(x,y,z,t)"
],
"Name": [
"Schwarz Cylinder"
],
"Xmax": [
"15"
],
"Xmin": [
"-15"
],
"Ymax": [
"25"
],
"Ymin": [
"-25"
],
"Zmax": [
"15"
],
"Zmin": [
"-15"
]
}
}

My question is: what is result of the code " if(isoCondition_0(x,y,z,t)<(0),-Schwarz(x,y,z,t),1)", or how to work for the code of "if(isoCondition_0(x,y,z,t)<(0),-Schwarz(x,y,z,t),1)".
I replace this code with "max(isoCondition_0(x,y,z,t)-(0),-Schwarz(x,y,z,t)), but I do not know how to work for the function of "max".
Could you please explain this? Thank you!

dayonghu1978
Posts: 10
Joined: Thu Dec 26, 2019 7:27 pm

### How to learn scripts?

I would like to build some models. But I do not the language used in Mathmod. Could you give me some suggestion about the scripts?

mathmod
Posts: 20
Joined: Mon Mar 25, 2019 9:06 am

### Re: How to use the function "if" and "max"

Hi,
the if instruction is straightforward. To understand how it works in the script, you should first understand how an isosurface is generated: An isosurface is defined by f(x,y,z,t)=c where c is a constante (0 in general).
In the script, the value "1" is used to force f(x,y,z) to have a value different from 0
The "max" and "min" functions are usually used to performe CSG operations (Constructive Solid Geometry).

{
"Iso3D": {
"Component": [
"DifferenceSpheres",
"UnionSpheres",
"IntersectSpheres"
],
"Description": [
"Constructive Solid Geometry (CSG) by Abderrahman Taha 18/11/2019"
],
"Fxyz": [
"((x-7/10)*(x-7/10)+y*y+z*z-1)*min(((x-7/10)*(x-7/10)+y*y+z*z-1),((x+3/10)*(x+3/10)+y*y+z*z-1))+1/50",
"min(((x-47/10)*(x-47/10)+y*y+z*z-1),((x-7/2)*(x-7/2)+y*y+z*z-1))",
"max(((x-7/10)*(x-7/10)+y*y+z*z-1),((x-2)*(x-2)+y*y+z*z-1))"
],
"Name": [
"CSG_Spheres"
],
"Xmax": [
"1/2",
"6",
"2"
],
"Xmin": [
"-2",
"2",
"0"
],
"Ymax": [
"2",
"2",
"2"
],
"Ymin": [
"-2",
"-2",
"-2"
],
"Zmax": [
"2",
"2",
"2"
],
"Zmin": [
"-2",
"-2",
"-2"
]
}
}
Attachments
csg.jpg (155.93 KiB) Viewed 621 times

mathmod
Posts: 20
Joined: Mon Mar 25, 2019 9:06 am

### Re: How to learn scripts?

Hi,
MathMod scripts are in JSON file format.
I would suggest you some practice by making a simple script or taking one from MathMod collection (for example "Schwarz") and modify it and see the result on the screen

dayonghu1978
Posts: 10
Joined: Thu Dec 26, 2019 7:27 pm

### Re: How to use the function "if" and "max"

(1)isoTransform=if(isoCondition_0(x,y,z,t)<(0),-Schwarz(x,y,z,t),1)

I could consider this could can obtain: f(x,y,z,t)= -Schwarz(x,y,z,t)+1=0 when isoCondition_0(x,y,z,t)<(0).

(2)isoTransform=if(isoCondition_0(x,y,z,t)<(0),-Schwarz(x,y,z,t),1)+exp(isoCondition_1(x,y,z,t))

For this code, I understand this code can get this result: f(x,y,z,t)=-Schwarz(x,y,z,t)+1+exp(isoCondition_1(x,y,z,t)) =0 when isoCondition_0(x,y,z,t)<(0) .

(3) isoTransform=if(isoCondition_0(x,y,z,t)<(0),-Schwarz(x,y,z,t),1)+exp(isoCondition_1(x,y,z,t))
For this code, I modify the "1", for example, "isoTransform=if(isoCondition_0(x,y,z,t)<(0),-Schwarz(x,y,z,t),0)+exp(isoCondition_1(x,y,z,t))" or "isoTransform=if(isoCondition_0(x,y,z,t)<(0),-Schwarz(x,y,z,t),3)+exp(isoCondition_1(x,y,z,t))". The values do not have any effect the results.
I do not know the results are right or wrong?

dayonghu1978
Posts: 10
Joined: Thu Dec 26, 2019 7:27 pm

### Re: How to approximate a surface that was cut using a condition function

What is the difference between the condition and "if" function?

mathmod
Posts: 20
Joined: Mon Mar 25, 2019 9:06 am

### Re: How to approximate a surface that was cut using a condition function

Huummm...difficult to respond to your question.
Sometimes, you don't want to use a condition in the script especially if you need to 3D print your model.

dayonghu1978
Posts: 10
Joined: Thu Dec 26, 2019 7:27 pm

### Re: How to approximate a surface that was cut using a condition function

{
"Iso3D": {
"Cnd": [
"x*x+y*y+z*z-1<(0) "
],
"Component": [
"Clebsch"
],
"Fxyz": [
"81*(x^3+y^3+z^3)-189*(x^2*y+x^2*z+y^2*x+y^2*z+z^2*x+z^2*y) +54*x*y*z+126*(x*y+x*z+y*z)-9*(x^2+y^2+z^2)-9*(x+y+z)+1"
],
"Name": [
"Clebsch"
],
"Xmax": [
" 1"
],
"Xmin": [
"-1"
],
"Ymax": [
" 1"
],
"Ymin": [
"-1"
],
"Zmax": [
" 1"
],
"Zmin": [
"-1"
]
}
}

In the above case, the condition function is x*x+y*y+z*z-1<(0). If I move this condition(x*x+y*y+z*z-1<(0)) to a "if" function, i.e.,
{
"Iso3D": {
"Component": [
"Clebsch"
],
"Fxyz": [
"if(x*x+y*y+z*z-1<(0),(81*(x^3+y^3+z^3)-189*(x^2*y+x^2*z+y^2*x+y^2*z+z^2*x+z^2*y) +54*x*y*z+126*(x*y+x*z+y*z)-9*(x^2+y^2+z^2)-9*(x+y+z)+1),1)"
],
"Name": [
"Clebsch"
],
"Xmax": [
" 1"
],
"Xmin": [
"-1"
],
"Ymax": [
" 1"
],
"Ymin": [
"-1"
],
"Zmax": [
" 1"
],
"Zmin": [
"-1"
]
}
}
I will get a different result (please see the attachment). I could not understand why they have this difference.
Attachments

dayonghu1978
Posts: 10
Joined: Thu Dec 26, 2019 7:27 pm

### How to calculate: exp(isoCondition_1(x,y,z,t)) after "if" function

{
"Iso3D": {
"Component": [
"Schwarz Cylinder"
],
"Const": [
"N=8"
],
"Description": [
"Schwarz Cylinder by Abderrahman Taha 05/12/2015"
],
"Funct": [
"Schwarz=cos(x) + cos(y) + cos(z)",
"isoCondition_0=(x^2-3.2^2)",
"isoCondition_1=(x^2-2.6^2)",
"isoTransform=if(isoCondition_0(x,y,z,t)<(0),-Schwarz(x,y,z,t),1)+exp(isoCondition_1(x,y,z,t))",
"isoTransform2=isoTransform((sqrt(x*x+z*z)-12),y,N*atan2(z,x),t)"
],
"Fxyz": [
"-isoTransform2(x,y,z,t)"
],
"Name": [
"Schwarz Cylinder"
],
"Xmax": [
"15"
],
"Xmin": [
"-15"
],
"Ymax": [
"25"
],
"Ymin": [
"-25"
],
"Zmax": [
"15"
],
"Zmin": [
"-15"
]
}
}
In this case, for this code:"isoTransform=if(isoCondition_0(x,y,z,t)<(0),-Schwarz(x,y,z,t),1)+exp(isoCondition_1(x,y,z,t))", I guess as following:
(1) if(isoCondition_0(x,y,z,t)<(0) /// this mean adding a cube space within two parallel surfaces (x=3.2 and x=-3.2)
(2) then an isosurface "-Schwarz(x,y,z,t)" will be formed in this cube space between two parallel surfaces.
*************************************************************************************************************************************
(3) I could not understand how to calculate exp(isoCondition_1(x,y,z,t)) because due to the condition of -3.2<x<3.2, exp(isoCondition_1(x,y,z,t)) will result in a large value if x=3.2 or -3.2.
So for exp(isoCondition_1(x,y,z,t)), it should be a small number and x should take the value less than 2.6. But I don't know the reason.

dayonghu1978
Posts: 10
Joined: Thu Dec 26, 2019 7:27 pm

### A question in CloseIso

{
"Iso3D": {
"Component": [
"CloseIso"
],
"Description": [
" CloseIso by Abderrahman taha 28/11/2018"
],
"Fxyz": [
"if((x^10+y^10+z^10<200000),-(cos(x)+cos(y)+cos(z)),(x^10 + y^10 +z^10 - 200000))"
],
"Name": [
"CloseIso"
],
"Xmax": [
"4"
],
"Xmin": [
"-4"
],
"Ymax": [
"4"
],
"Ymin": [
"-4"
],
"Zmax": [
"4"
],
"Zmin": [
"-4"
]
}
}
In this code: if((x^10+y^10+z^10<200000),-(cos(x)+cos(y)+cos(z)),(x^10 + y^10 +z^10 - 200000)), I think (x^10+y^10+z^10<200000) would set up a cube space condition, and -(cos(x)+cos(y)+cos(z)) would form a isosurface, but I could not understand the effect of the code"(x^10 + y^10 +z^10 - 200000)". When I replace the "(x^10 + y^10 +z^10 - 200000)" with "1", I could get the same results.
Attachments