How to use the makerjs.angle function in makerjs

To help you get started, weā€™ve selected a few makerjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mrzealot / absolem / plans / absolem.js View on Github external
const fix_corner_raw = (a, mirrored_a, b, mirrored_b, outer, target) => {

    const center = m.path.intersection(a, b).intersectionPoints[0]
    const angle_a = m.angle.ofLineInDegrees(a) + (mirrored_a ? 180 : 0)
    const angle_b = m.angle.ofLineInDegrees(b) + (mirrored_b ? 180 : 0)
    const angle = angle_b - angle_a
    let radius = Math.tan(m.angle.toRadians(Math.abs(angle) / 2)) * corner_radius
    const sign = radius > 0 ? 1 : -1
    radius = Math.abs(radius)
    const circ = circle(center, radius)
    const cas = m.path.intersection(a, circ).intersectionPoints
    const cbs = m.path.intersection(b, circ).intersectionPoints
    
    // there can be multiple intersections, so we want the points
    // furthest from the control (either inner or outer) point
    const furthest = (arr, control) => {
        let max
        let max_dist = 0

        for (const point of arr) {
github mrzealot / absolem / plans / absolem.js View on Github external
const fix_corner_raw = (a, mirrored_a, b, mirrored_b, outer, target) => {

    const center = m.path.intersection(a, b).intersectionPoints[0]
    const angle_a = m.angle.ofLineInDegrees(a) + (mirrored_a ? 180 : 0)
    const angle_b = m.angle.ofLineInDegrees(b) + (mirrored_b ? 180 : 0)
    const angle = angle_b - angle_a
    let radius = Math.tan(m.angle.toRadians(Math.abs(angle) / 2)) * corner_radius
    const sign = radius > 0 ? 1 : -1
    radius = Math.abs(radius)
    const circ = circle(center, radius)
    const cas = m.path.intersection(a, circ).intersectionPoints
    const cbs = m.path.intersection(b, circ).intersectionPoints
    
    // there can be multiple intersections, so we want the points
    // furthest from the control (either inner or outer) point
    const furthest = (arr, control) => {
        let max
        let max_dist = 0

        for (const point of arr) {
            const d = m.measure.pointDistance(point, control)
            if (d > max_dist) {
                max_dist = d
github microsoft / maker.js / demos / card.js View on Github external
function findAndFlip(arcId, origin) {
	        var arc = roundRect.paths[arcId];
	        arc.startAngle = makerjs.angle.mirror(arc.startAngle, true, true);
	        arc.endAngle = makerjs.angle.mirror(arc.endAngle, true, true);
	        arc.origin = origin;
        }
github microsoft / maker.js / demos / js / arc-text.js View on Github external
var height = measure.high[1];
    var h2 = height / 2;
    var left = measure.low[0];
    var right = measure.high[0];
    var textWidth = right - left;

    if (showCircle) {
        this.paths = { 
            arc: arc,
            circleT: new makerjs.paths.Circle(arcRadius + h2),
            circleB: new makerjs.paths.Circle(arcRadius - h2)
        };
    }

    //move each character to a percentage of the total arc
    var span = makerjs.angle.ofArcSpan(arc);
    for (var i = 0; i < text.length; i++) {
        var char = textModel.models[i];

        //get the x distance of each character as a percentage
        var distFromFirst = char.origin[0] - left;
        var center = distFromFirst / textWidth;

        //set a new origin at the center of the text
        var o = makerjs.point.add(char.origin, [0, h2]);
        makerjs.model.originate(char, o);

        //project the character x position into an angle
        var angle = center * span;
        var angleFromEnd = onTop ? endAngle - angle : startAngle + angle;
        var p = makerjs.point.fromAngleOnCircle(angleFromEnd, arc);
        char.origin = p;
github microsoft / maker.js / demos / card.js View on Github external
function findAndFlip(arcId, origin) {
	        var arc = roundRect.paths[arcId];
	        arc.startAngle = makerjs.angle.mirror(arc.startAngle, true, true);
	        arc.endAngle = makerjs.angle.mirror(arc.endAngle, true, true);
	        arc.origin = origin;
        }
github microsoft / maker.js / demos / js / makerjs-heart.js View on Github external
function Heart(r, a2) {

    var a = a2 / 2;

    var a_radians = makerjs.angle.toRadians(a);

    var x = Math.cos(a_radians) * r;
    var y = Math.sin(a_radians) * r;

    var z = makerjs.solvers.solveTriangleASA(90, 2 * r, 90 - a);

    this.paths = {
        arc1: new makerjs.paths.Arc([x , 0], r, -a, 180 - a),
        line1: new makerjs.paths.Line([x * 2, -y], [0, -z + y])
    };

    this.paths.arc2 = makerjs.path.mirror(this.paths.arc1, true, false);
    this.paths.line2 = makerjs.path.mirror(this.paths.line1, true, false);
}

makerjs

Maker.js, a Microsoft Garage project, is a JavaScript library for creating and sharing modular line drawings for CNC and laser cutters.

Apache-2.0
Latest version published 6 months ago

Package Health Score

74 / 100
Full package analysis