Skip to content

Conversation

@SimonAndreys
Copy link

Re-wrote the function calculate-circle-center-3pt in src/utils.typ
Previously, this function took three 3D vectors as input but was essentially 2D, taking the z-coordinate from the first vector. Now the output is the center of the circle passing through the 3 point even if they have not the same z-coordinates.
Note : if two of the points are equal, there is no uniqueness of the circle center. Originally it returned the center passing through the 2 different points with x-coordinate 0, which seems arbitrary. Now it returns the midpoint between the two different points.
The function fails if the 3 points are aligned and different.
This is a first step towards making arc-through and circle-through work with 3D points with different z-coordinates.
All test passed.

@johannes-wolf johannes-wolf self-requested a review January 31, 2026 12:52
@johannes-wolf johannes-wolf added this to the 0.5.0 milestone Jan 31, 2026
Copy link
Member

@johannes-wolf johannes-wolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Some small things to fix. I have not yet tested it.

src/util.typ Outdated
if args.len() == 4 { break }
}
// If two points are the same we take the midpoint with the two other.
if a == b or b == c { return ligne-pt(a, c, 0.5) } else if a == c { return line-pt(a, b, 0.5) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: ligne-ptline-pt – maybe we should change that to vector.lerp.

src/util.typ Outdated
let vw = vx * wx + vy * wy + vz * wz // <v, w>
let denom = 2 * (v2 * w2 - calc.pow(vw, 2)) // 2*norm of "v cross w"
// if the points are aligned, we fail with error message returning the coordinates of the points
assert(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Typst evaluates all arguments of assert, this should be a panic inside an if.

+ str(c.at(2))
+ ") ",
)
let lambda = w2 * (v2 - vw) / denom
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use typstyle to format the code, linebreaks and indentation are automatic... I put this string back to one line.

src/util.typ Outdated
// If two points are the same we take the midpoint with the two other.
if a == b or b == c { return ligne-pt(a, c, 0.5) } else if a == c { return line-pt(a, b, 0.5) }
// we compute the vectors b-a and c-a and the norm of their cross product
let (vx, vy, vz) = (0, 1, 2).map(i => b.at(i) - a.at(i)) // v=b-a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use range(0, 2) instead of (0, 1, 2) – same for line 114 and 145.

@johannes-wolf johannes-wolf self-requested a review February 2, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants