hermann on Tue, 26 Dec 2023 02:17:28 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: norml2() with variables in vector? | GP->OpenSCAD


Just realized that "qfminim(M,n)" does not really help.

After right multiplying to Q the vectors are just all integer coordinate points in sphere with radius <=n:

https://stamm-wilbrandt.de/images/5*17+4%5E2.png

From radius 0 ([0,0,0]), over 1 ([0,0,1], [0,1,0], ..., [-1,0,0]) to n.
All integer radii besides those of the form 4^k*7 are present.
In the screenshot only vectors with norml2()=n are blue.

OpenSCAD screenshot of file created with this command:

sos=1 p=5 q=17 sq=4 gp -q < t2.gp > t2.scad


Script:
$ cat t2.gp
readvec("tqf.gp");

sph(coord)=print("translate(",coord,") sphere(0.25);");
col(name)=print("color(\"",name,"\",1.0)");

sos=eval(getenv("sos"));
p=eval(getenv("p")); q=eval(getenv("q")); sq=eval(getenv("sq"));

n=p*q+sq^2;
Q=qflllgram(get_tqf(n))^-1;

M=Q~*Q;
S=[x|x<-Vec(qfminim(M,n)[3]),qfeval(M,x)==n]; S=concat(S,-S);
S2=[x|x<-Vec(qfminim(M,n)[3]),qfeval(M,x)<n]; S2=concat(S2,-S2);

{
  print("$fn=20;");
  if(!eval(getenv("sos")),
    foreach(S,s,col("blue");sph(s~));
    foreach(S2,s,sph(s~))
    ,
    foreach(S,s,
      if(vecsearch(vecsort(abs(Q*s)),sq),col("blue"));
      sph((Q*s)~));
    foreach(S2,s,
      sph((Q*s)~)));
}
$

Regards,

Hermann.

On 2023-12-11 22:37, hermann@stamm-wilbrandt.de wrote:
On 2023-12-08 17:43, Bill Allombert wrote:
Ah yes, qfminim only return the solution with positive first coordinates.
If you want the others, just negate the result:
M=v~*v;S=[x|x<-Vec(qfminim(M,101)[3]),qfeval(M,x)==101];
concat(S,-S)

Cheers,
Bill.

Thanks, good to know that just negation gives the others.

I wanted to visualize the 3-dimensional coordinates, and remembered
that I did that often with OpenSCAD in the past.

While "a picture says more than 1000 words", for 3D being able
to translate, rotate and zoom is the equivalent.

Below openscad_demo.gp adds to the short code sofar.
In order to enable a view without installing openscad,
I did screen recording with peek.


With sos=0 the vectors before mapping with matrix v are displayed.
All points are on a plane, the blue dots are with qfeval=101,
the other dots with qfeval<101. Interesting structure:
https://stamm-wilbrandt.de/images/Peek_2023-12-11_22-24.gif


With sos=1 (sum of squares) the sum of 3 squares are displayed,
which are on sphere with radius 101:
https://stamm-wilbrandt.de/images/Peek_2023-12-11_22-21.gif


pi@raspberrypi5:~ $ cat openscad_demo.gp
\\ PARI/GP->openscad demo
\\ sos=1 displays sum of 3 squares sphere, sos=0 the pre mapping plane
\\
\\ Try: sos=1 gp -q < openscad_demo.gp > gp.scad
\\
sph(coord)=print("translate(",coord,") sphere(0.4);");
col(name)=print("color(\"",name,"\",1.0)");

v=[-102, -107, 93; 22, 23, -20; 1, 1, -1]~;
M=v~*v;
S=[x|x<-Vec(qfminim(M,101)[3]),qfeval(M,x)==101];
S2=[x|x<-Vec(qfminim(M,101)[3]),qfeval(M,x)<101];

{
  print("$fn=20;");
  if(!eval(getenv("sos")),
    foreach(S,s,col("blue");sph(s~));
    foreach(S2,s,sph(s~))
    ,
    foreach(S,s,
      if(vecsearch(abs(s),4),col("black"));
      sph((v*s)~)))
}
pi@raspberrypi5:~ $


Regards,

Hermann.