In this case I think the answer is in the lack(?) of anti-aliasing for the renderer used (ref. smooth()).
(Provided quark’s assumtions above is correct, in that there’s no errors in your custom classes).
Still using Processing 3.5.4 btw. Maybe it’s different for the new version?
size(820, 400, P2D);
smooth(3); // try 2,3,4 or 8
Based on quarks code above I made this little test:
Click to (un) expand
/* Quadratic Bezier test 1
Based on quarks cubic Bezier
https://discourse.processing.org/t/why-is-built-in-bezier-function-more-smooth-than-my-custom-bezier-function/31833/3
2021.08.25
*/
PVector pp1 = new PVector(100, 260), pp2 = new PVector(180, 340),
pp3 = new PVector(625, 340), pp4 = new PVector(800, 260);
PVector pc1 = new PVector(100, 100),
pc2 = new PVector(350, 180),
pc3 = new PVector(800, 100);
void setup() {
size(820, 400, P2D);
smooth(3); // try 2,3,4 or 8
//noSmooth();
background(255);
noFill();
stroke(0);
strokeWeight(6);
drawQuadraticCurve(pc1, pc2, pc3);
//stroke(90, 200, 90);
//strokeWeight(2);
//drawCubicCurve(pp1, pp2, pp3, pp4);
bezier(pp1.x, pp1.y, pp2.x, pp2.y, pp3.x, pp3.y, pp4.x, pp4.y);
}
void drawCubicCurve(PVector p1, PVector p2, PVector p3, PVector p4) {
PVector prevP = cubicBezier(p1, p2, p3, p4, 0);
float deltaT = 0.001;
for (float i = deltaT; i <= 1; i += deltaT) {
PVector nextP = cubicBezier(p1, p2, p3, p4, i);
line(nextP.x, nextP.y, prevP.x, prevP.y);
prevP = nextP;
}
}
PVector cubicBezier(PVector p1, PVector p2, PVector p3, PVector p4, float value) {
PVector r1 = PVector.lerp(p1, p2, value);
PVector r2 = PVector.lerp(p2, p3, value);
PVector r3 = PVector.lerp(p3, p4, value);
PVector r4 = PVector.lerp(r1, r2, value);
PVector r5 = PVector.lerp(r2, r3, value);
PVector r6 = PVector.lerp(r4, r5, value);
return r6;
}
void drawQuadraticCurve(PVector p1, PVector p2, PVector p3) {
PVector prevP = quadraticBezier(p1, p2, p3, 0);
float deltaT = 0.001;
for (float i = deltaT; i <= 1; i += deltaT) {
PVector nextP = quadraticBezier(p1, p2, p3, i);
line(nextP.x, nextP.y, prevP.x, prevP.y);
prevP = nextP;
}
}
PVector quadraticBezier(PVector p1, PVector p2, PVector p3, float value) {
PVector r1 = PVector.lerp(p1, p2, value);
PVector r2 = PVector.lerp(p2, p3, value);
PVector r3 = PVector.lerp(r1, r2, value);
return r3;
}
Btw what is the default renderer anyway?
I get different results from not specifying a renderer (= default), to specifying one. The default renderer doesn’t seem to have anti-aliasing at all? Yet the documentation states:
The default renderer uses smooth(3) by default
FX2D doesn’t seem to care about different smooth() settings either, but it’s still a bit more smoothed than the default renderer.
P2D with smooth(4) or (8) is the best, I haven’t compared side-by-side but I don’t see much if any difference. I have a decent-ish GPU so I don’t think it’s the hardware (then again I use glasses… )
EDIT: Slight correction: I switched up quadratic and cubic… Quark’s Bezier above is cubic, not quadratic. Reflected in code comments only, no change otherwise.
Oh and also, I believe the default renderer is named Java2D?