File:LogTestMapChatGPTv13.jpg
LogTestMapChatGPTv13.jpg (468 × 468 pixels, file size: 106 KB, MIME type: image/jpeg)
Summary
Complex map of function \( z\mapsto \ln(z) \)
generated at the poor resolution grid with the preliminary version of the plotter written by ChatGPT 2025.09.01
The picture is loaded in order to compare it to that generated with routine conto.cin from Citizendium [1].
The routine used and the driver (calling program, the generator of the pictire) are loaded in two sections below.
File ado.cin is also required; it is not duplicated here.
ContoArrayJump1.cin
//array-based marching-squares contour tracer (C++98 compatible)
//
// Signature:
// void conto_array(FILE* out, .. (this name caused confusions)
// void ContoArrayJump1(FILE* out,
// double *field, double *X, double *Y,
// int M, int N,
// double level,
// double max_jump);
//
// field is flattened, indexed as field[i + j*(M+1)], i=0..M, j=0..N
// X[0..M], Y[0..N] are the node coordinates (increasing).
// max_jump: if >0, edges whose corner values differ by > max_jump are skipped
// (useful to suppress drawing across branch cuts).
//
#ifndef CONTO_CIN_ONCE
#define CONTO_CIN_ONCE
#include <cstdio>
#include <cmath>
#include <cstdlib>
static const double EPS_ZERO = 1e-14;
struct Pt { double x, y; };
static inline Pt interp_edge(double xA,double yA,double fA,
double xB,double yB,double fB,double level)
{
Pt p;
double denom = (fB - fA);
if (fabs(denom) < EPS_ZERO) { p.x = 0.5*(xA + xB); p.y = 0.5*(yA + yB); }
else {
double t = (level - fA) / denom;
p.x = xA + t*(xB - xA);
p.y = yA + t*(yB - yA);
}
return p;
}
static inline void draw_seg(FILE* out, const Pt &a, const Pt &b) {
if (!out) return;
std::fprintf(out, "newpath %.12g %.12g moveto %.12g %.12g lineto stroke\n", a.x, a.y, b.x, b.y);
}
// void conto_array(FILE* out,
void ContoArrayJump1(
FILE* out,
double *field, double *X, double *Y,
int M, int N,
double level,
double max_jump)
{
if (!out || !field || !X || !Y) return;
if (M <= 0 || N <= 0) return;
int NX = M + 1;
// loop cells (i=0..M-1, j=0..N-1)
for (int j = 0; j < N; ++j) {
double y0 = Y[j], y1 = Y[j+1];
for (int i = 0; i < M; ++i) {
double x0 = X[i], x1 = X[i+1];
// corners: bottom-left (f00), bottom-right (f10),
// top-right (f11), top-left (f01)
double f00 = field[i + j*NX];
double f10 = field[(i+1) + j*NX];
double f11 = field[(i+1) + (j+1)*NX];
double f01 = field[i + (j+1)*NX];
// quick skip: all strictly same side of level
if ((f00 - level) > 0.0 && (f10 - level) > 0.0 && (f11 - level) > 0.0 && (f01 - level) > 0.0) continue;
if ((f00 - level) < 0.0 && (f10 - level) < 0.0 && (f11 - level) < 0.0 && (f01 - level) < 0.0) continue;
// compute edge intersections (consistent endpoint ordering)
// edge 0: bottom (x0,y0)->(x1,y0)
// edge 1: right (x1,y0)->(x1,y1)
// edge 2: top (x0,y1)->(x1,y1)
// edge 3: left (x0,y0)->(x0,y1)
Pt edge[4];
bool has[4] = { false, false, false, false };
// bottom
if ((f00 - level)*(f10 - level) < 0.0) {
if (max_jump <= 0.0 || fabs(f00 - f10) <= max_jump) {
edge[0] = interp_edge(x0,y0,f00, x1,y0,f10, level); has[0] = true;
}
}
// right
if ((f10 - level)*(f11 - level) < 0.0) {
if (max_jump <= 0.0 || fabs(f10 - f11) <= max_jump) {
edge[1] = interp_edge(x1,y0,f10, x1,y1,f11, level); has[1] = true;
}
}
// top
if ((f11 - level)*(f01 - level) < 0.0) {
if (max_jump <= 0.0 || fabs(f11 - f01) <= max_jump) {
edge[2] = interp_edge(x0,y1,f01, x1,y1,f11, level); has[2] = true;
}
}
// left
if ((f01 - level)*(f00 - level) < 0.0) {
if (max_jump <= 0.0 || fabs(f01 - f00) <= max_jump) {
edge[3] = interp_edge(x0,y0,f00, x0,y1,f01, level); has[3] = true;
}
}
// collect present edges in bottom,right,top,left order
int idxs[4]; int k = 0;
for (int e = 0; e < 4; ++e) if (has[e]) idxs[k++] = e;
if (k == 2) {
// normal case: draw segment
Pt a = edge[idxs[0]], b = edge[idxs[1]];
draw_seg(out, a, b);
continue;
}
if (k == 4) {
// ambiguous saddle -> draw both vertical and horizontal crossings (an X)
Pt pb = edge[0], pr = edge[1], pt = edge[2], pl = edge[3];
// bottom-to-top and left-to-right
draw_seg(out, pb, pt);
draw_seg(out, pl, pr);
continue;
}
// handle corner-equalities using small bishop diagonal rule
bool c00eq = fabs(f00 - level) < EPS_ZERO;
bool c10eq = fabs(f10 - level) < EPS_ZERO;
bool c01eq = fabs(f01 - level) < EPS_ZERO;
bool c11eq = fabs(f11 - level) < EPS_ZERO;
// opposite corners equal -> full diagonal
if ((c00eq && c11eq) || (c10eq && c01eq)) {
Pt a,b;
if (c00eq && c11eq) { a.x = x0; a.y = y0; b.x = x1; b.y = y1; }
else { a.x = x1; a.y = y0; b.x = x0; b.y = y1; }
draw_seg(out, a, b);
continue;
}
// single corner equals -> small bishop diagonal through corner
if ( (c00eq && !c10eq && !c01eq && !c11eq) ||
(c10eq && !c00eq && !c11eq && !c01eq) ||
(c11eq && !c10eq && !c01eq && !c00eq) ||
(c01eq && !c00eq && !c11eq && !c10eq) ) {
Pt p,q;
if (c00eq) { p.x = x0; p.y = y0; q.x = x1; q.y = y1; }
else if (c10eq) { p.x = x1; p.y = y0; q.x = x0; q.y = y1; }
else if (c11eq) { p.x = x1; p.y = y1; q.x = x0; q.y = y0; }
else { p.x = x0; p.y = y1; q.x = x1; q.y = y0; }
draw_seg(out, p, q);
continue;
}
// otherwise nothing to draw in this cell
}
}
}
#endif // CONTO_CIN_ONCE
LogTestMapChatGPTv13.cc
// files ado.cin and "ContoArrayJump1.cin" above should be loaded in order to compile the generator below.
#include <stdio.h>
#include <stdlib.h>
#define DB double
#define DO(x,y) for(x=0;x<y;x++)
#include<complex>
typedef std::complex<double> z_type;
#define Re(x) x.real()
#define Im(x) x.imag()
#define I z_type(0.,1.)
#include "ado.cin"
#include "ContoArrayJump1.cin"
z_type F(z_type z) {return log(z);}
int main(){ int j,k,m,n; DB x,y, p,q, t; z_type z,c,d, cu,cd;
int M=41,M1=M+1;
int N=41,N1=N+1;
DB X[M1],Y[N1]; DB *g, *f, *w; // w is working array.
g=(DB *)malloc((size_t)((M1*N1)*sizeof(DB)));
f=(DB *)malloc((size_t)((M1*N1)*sizeof(DB)));
w=(DB *)malloc((size_t)((M1*N1)*sizeof(DB)));
char v[M1*N1]; // v is working array
//FILE *o;o=fopen("QuadraticMapByChatGPTtest11.eps","w"); ado(o,422,422);
//FILE *o;o=fopen("F1zChatGPTtest.eps","w"); ado(o,422,422);
//FILE *o;o=fopen("09.eps","w"); ado(o,422,422);
FILE *o;o=fopen("LogTestMapChatGPTv13.eps","w"); ado(o,422,422);
fprintf(o,"210 210 translate\n 100 100 scale\n");
fprintf(o,"1 setlinejoin 2 setlinecap\n");
fprintf(o,"/W { setlinewidth } def\n");
fprintf(o,"/RGB { setrgbcolor } def\n");
fprintf(o,"/S { stroke } def\n");
#define M(x,y) fprintf(o,"%6.3f %6.3f M\n",0.+x,0.+y);
#define L(x,y) fprintf(o,"%6.3f %6.3f L\n",0.+x,0.+y);
DO(m,M1) X[m]=-2+.1*(m-.4);
DO(n,N1) Y[n]=-2+.1*(n-.3);
for(m=-2;m<3;m++){M(m,-2) L(m,2)}
for(n=-2;n<3;n++){M(-2,n) L(2,n)}
fprintf(o,".01 W 0 0 0 RGB S\n");
DO(m,M1)DO(n,N1){ g[m*N1+n]=999;
f[m*N1+n]=999;}
DO(m,M1){x=X[m]; if(m/10*10==m) printf("x=%6.3f\n",x);
DO(n,N1){y=Y[n]; z=z_type(x,y); //if(abs(z+2.)>.019)
c=F(z);
p=Re(c); q=Im(c); if(p>-99 && p<99 )
//{ g[m*N1+n]=p;f[m*N1+n]=q;}
{ g[m+N1*n]=p;f[m+M1*n]=q;}
}}
fprintf(o,"1 setlinejoin 1 setlinecap\n"); p=2.;q=1.;
fprintf(o,".01 W 0 .6 0 RGB\n"); for(m=-3;m<3;m++)for(n=2;n<10;n+=2)ContoArrayJump1(o,f,X,Y,M,N,(m+.1*n),q);
fprintf(o,".01 W .8 0 0 RGB\n"); for(m=0;m<3;m++) for(n=2;n<10;n+=2)ContoArrayJump1(o,g,X,Y,M,N,-(m+.1*n),q);
fprintf(o,".01 W 0 0 .8 RGB\n"); for(m=0;m<3;m++) for(n=2;n<10;n+=2)ContoArrayJump1(o,g,X,Y,M,N, (m+.1*n),q);
fprintf(o,".02 W 0 0 .8 RGB\n"); for(m= 1;m<5;m++) ContoArrayJump1(o,f,X,Y,M,N, (0.+m),p);
fprintf(o,".02 W .8 0 0 RGB\n"); for(m= 1;m<5;m++) ContoArrayJump1(o,f,X,Y,M,N, (0.-m),p);
fprintf(o,".02 W .5 0 .5 RGB\n"); ContoArrayJump1(o,f,X,Y,M,N, (0. ),p);
fprintf(o,".02 W 0 0 0 RGB\n"); for(m=-10;m<11;m++)ContoArrayJump1(o,g,X,Y,M,N,(0.+m),p);
fprintf(o,"showpage\n"); fprintf(o,"%c%cTrailer\n",'%','%');
fclose(o); free(f); free(g); free(w);
system("epstopdf LogTestMapChatGPTv13.eps");
system( "open LogTestMapChatGPTv13.pdf"); //for macintosh
}
References
- ↑ https://en.citizendium.org/wiki/Contour_plot/Code/conto.cin // Copyleft 2008 by Dmitrii Kouznetsov This page was last modified 01:05, 2 February 2009.
Keywords
«Ado.cin», «ChatGPT», «Conto.cin», «Contour plot», «Log», «LogTestMaps», «ContoTestMaps»,
File history
Click on a date/time to view the file as it appeared at that time.
| Date/Time | Thumbnail | Dimensions | User | Comment | |
|---|---|---|---|---|---|
| current | 16:08, 2 September 2025 | 468 × 468 (106 KB) | T (talk | contribs) | == Summary == {{oq|LogTestMapChatGPTv13.jpg|LogTestMapChatGPTv13.jpg (468 × 468 pixels, file size: 106 KB, MIME type: image/jpeg)}} Complex map of function \( z\mapsto \ln(z) \) generated at the poor resolution grid with the preliminary version of the plotter written by ChatGPT 2025.09.01 The picture is loaded in order to compare it to that generated with routine conto.cin from Citizendium <ref> https://en.citizendium.org/wiki/Contour_plot/Code/conto.cin // Copyleft 2008 by Dmit... |
You cannot overwrite this file.
File usage
The following page uses this file:
