connector curves #88
Replies: 2 comments 4 replies
-
|
Can you explain how it works? |
Beta Was this translation helpful? Give feedback.
-
|
I did that, though I'm not sure I like it... class Vector2D {
...
normalize() {
let l = this.length();
return new Vector2D(this.x / l, this.y / l);
}
reach(l) {
return this.normalize().mul(l);
}
...
}I left the function connectorCurve(p1, p2) {
[p1, p2] = [v(p1), v(p2)];
const diff = p2.sub(p1);
const dist = diff.length();
const sweepRadius = Math.min(dist * .2, 50);
const tanDiff = diff.add(v(0, sweepRadius * 2 * (diff.y > 0 ? -1 : 1)))
const tanDist = tanDiff.length();
const tanTerm = tanDist**2 - (sweepRadius*2)**2;
const tanRad = tanTerm **.5;
const numerator = tanTerm + tanRad**2;
const x = numerator/(2*tanDist);
const y = ((4*tanDist**2*tanRad**2 - numerator**2)/(4*tanDist**2))**.5 * (diff.y <= 0 ? -1 : 1);
const tanP = tanDiff.reach(x).add(tanDiff.rotate(Math.PI/2).reach(y));
const angle = tanP.angle();
const arcEnd = v(0, 0).rotateAround(angle, v(0, (diff.y < 0 ? -1 : 1) * sweepRadius));
return `M${p1} A${sweepRadius},${sweepRadius} 0 ${angle * diff.y < 0 ? 1 : 0},${diff.y > 0 ? 1 : 0} ${p1.add(arcEnd)} L${p2.sub(arcEnd)} A${sweepRadius},${sweepRadius} 0 ${angle * diff.y < 0 ? 1 : 0},${diff.y < 0 ? 1 : 0} ${p2}`;
}This is nearly the same concept as described above, the only difference being the angle at which the arcs stop. This new angle causes the bezier to degenerate to a line, so it has been substituted accordingly. Find the distance between the two sockets we're connecting. |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm building a node language of my own, and one thing that I've never been satisfied with in any node language I've used is the curvature of the connectors. I am not satisfied with what I have created either, but I do think it an improvement. I'm testing it on NoiseCraft because my node language is not in a usable state yet.

Here's how I'm calculating the path:
Beta Was this translation helpful? Give feedback.
All reactions