Skip to content

Commit

Permalink
normalize theta; bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bobnik committed Oct 15, 2024
1 parent 69d871c commit 230ab0a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
12 changes: 9 additions & 3 deletions src/common/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@ export const downsample = (vertices, tolerance = 0.0001) => {
return result
}

// Normalize the theta value to the range [0, 2*pi)
export const normalizeTheta = (theta) => {
const TWO_PI = Math.PI * 2

return ((theta % TWO_PI) + TWO_PI) % TWO_PI
}

// Convert x,y vertices to theta, rho vertices
export const toThetaRho = (subsampledVertices, maxRadius, rhoMax) => {
let vertices = []
Expand All @@ -389,8 +396,7 @@ export const toThetaRho = (subsampledVertices, maxRadius, rhoMax) => {
subsampledVertices[next].x,
subsampledVertices[next].y,
)
// Convert to [0, 2pi]
rawTheta = (rawTheta + 2.0 * Math.PI) % (2.0 * Math.PI)
rawTheta = normalizeTheta(rawTheta)

// Compute the difference to the last point.
let deltaTheta = rawTheta - previousRawTheta
Expand All @@ -407,7 +413,7 @@ export const toThetaRho = (subsampledVertices, maxRadius, rhoMax) => {

previousRawTheta = rawTheta
previousTheta = theta
vertices.push(new Victor(theta, rho))
vertices.push(new Victor(normalizeTheta(theta), rho))
}

return vertices
Expand Down
14 changes: 0 additions & 14 deletions src/features/export/ScaraGCodeExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@ export default class ScaraGCodeExporter extends GCodeExporter {
this.offsetY = 0
}

// collects stats for use in PRE and POST blocks
collectStats(vertices) {
return {
mintheta: Math.min(...vertices.map((v) => v.x)),
minrho: Math.min(...vertices.map((v) => v.y)),
maxtheta: Math.max(...vertices.map((v) => v.x)),
maxrho: Math.max(...vertices.map((v) => v.y)),
starttheta: vertices[0].x,
startrho: vertices[0].y,
endtheta: vertices[vertices.length - 1].x,
endrho: vertices[vertices.length - 1].y,
}
}

// transforms vertices into a SCARA GCode format
transformVertices(vertices) {
vertices = toScaraGcode(
Expand Down

0 comments on commit 230ab0a

Please sign in to comment.