Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi,

I'm quite amazed how smooth the lines are! I'm quite curious as to how you came up with the formula for calculating the offsets when adding points (link): const offset = vec.mul(vec.per(vec.lrp(nextVector, vector, dpr)), radius).

I noticed that it used to be const offset = vec.mul(vec.per(vector), radius) in an older commit. There's also currently a similar looking formula for finding the offset when drawing caps at sharp corners (link): const offset = vec.mul(vec.per(prevVector), radius).

I tried drawing a few diagrams but it doesn't seem obvious to me how it works (why linearly interpolate the dot product between the two unit vectors?). Also, when drawing caps at a point, why is the offset vec.mul(vec.per(prevVector), radius) rather than vec.mul(vec.per(vector), radius)?

Thanks!

You must be logged in to vote

Ah the many weird corners of this algorithm. The answer is generally “lots of trial and error” mixed with “trying everything and seeing what worked”.

The first question has to do with pressure: the more pressure, the greater the radius, and so the greater the risk (iirc) of strange corners when a corner is not quite enough to create a cap. You can try the using the old offset code and drawing some upper case “M”s, and see if you can spot the difference.

The second question is easier to answer specifically: if we find a sharp corner, then the current vector is thrown out; we need to start the cap using the previous vector (which would have pointed to the current point).

Replies: 1 comment

Comment options

Ah the many weird corners of this algorithm. The answer is generally “lots of trial and error” mixed with “trying everything and seeing what worked”.

The first question has to do with pressure: the more pressure, the greater the radius, and so the greater the risk (iirc) of strange corners when a corner is not quite enough to create a cap. You can try the using the old offset code and drawing some upper case “M”s, and see if you can spot the difference.

The second question is easier to answer specifically: if we find a sharp corner, then the current vector is thrown out; we need to start the cap using the previous vector (which would have pointed to the current point).

You must be logged in to vote
0 replies
Answer selected by steveruizok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.