locked-joints.js

total 0
used 0
limit 0
/* --- title: Locked Joint files: ../point_src/core/head.js ../point_src/pointpen.js ../point_src/pointdraw.js ../point_src/pointlist.js ../point_src/point-content.js ../point_src/point.js ../point_src/events.js ../point_src/automouse.js ../point_src/distances.js ../point_src/dragging.js ../point_src/functions/clamp.js ../point_src/stage.js ../point_src/cone.js ../point_src/constrain-distance.js --- A point cannot exceed the rotation around a point to a maxmium angle value, relative to the origin point zero. Meaning if we have a point (origin), and another point (knee). The position of the knee may not lye outside a cone projected from the center of origin, Rotating the origin will slide the position around the origin center Moving the knee will _lock_ at the edges of the projected cone. distance is handled by another element, and is optional here. This demo uses two constraints together: 1. `cone()` limits the angle of the child around its parent. 2. `track()` keeps the child at a fixed distance from its parent. So the cone decides _where the point may rotate_, while track decides _how far away it stays_. Combining them gives a simple joint with angular limits. */ class MainStage extends Stage { canvas='playspace' mounted(){ let a = this.a = new Point({x:200,y:200, radius: 50, rotation: 10, coneDeg: 50}) let b = this.b = new Point({x:400,y:200, radius: 30, rotation: 0, /* degrees either side of rotation point. resulting in 10 arc degress allowed movement.*/ coneDeg: 10}) let c = this.c = new Point({x:600,y:200, radius: 20}) this.a.cone.update({ container: this.dimensions, innerOffset: 1, innerCurve: 1 }) this.dragging.add(a, b, c) } draw(ctx){ this.clear(ctx) // this.a.rotation += 1 /* First clamp each child into its parent's allowed angular cone. */ this.a.constraint.cone(this.b, this.a.coneDeg) this.b.constraint.cone(this.c, this.b.coneDeg) /* Then enforce the segment lengths. This preserves the locked angle while keeping each point on its radius from the parent. */ this.b.constraint.track(this.a, 200) this.c.constraint.track(this.b, 100) this.a.cone.fill(ctx, {color: '#010101'}) this.a.pen.indicator(ctx, {color:'#ddd'}) this.b.pen.indicator(ctx, {color:'green'}) this.c.pen.indicator(ctx) } } ;stage = MainStage.go();
Run
Meta Data
title Locked Joint
imports ()
files ('../point_src/core/head.js', '../point_src/pointpen.js', '../point_src/pointdraw.js', '../point_src/pointlist.js', '../point_src/point-content.js', '../point_src/point.js', '../point_src/events.js', '../point_src/automouse.js', '../point_src/distances.js', '../point_src/dragging.js', '../point_src/functions/clamp.js', '../point_src/stage.js', '../point_src/cone.js', '../point_src/constrain-distance.js')
unused_keys ()
unknown_keys ()
filepath_exists True
path locked-joints.js
filepath locked-joints.js
clean_files ('../point_src/core/head.js', '../point_src/pointpen.js', '../point_src/pointdraw.js', '../point_src/pointlistdraw.js', '../point_src/pointlistgradient.js', '../point_src/pointlistshape.js', '../point_src/pointlistgenerator.js', '../point_src/unpack.js', '../point_src/pointlist.js', '../point_src/compass.js', '../point_src/center.js', '../point_src/point-content.js', '../point_src/relative-xy.js', '../point_src/pointcast.js', '../point_src/point.js', '../point_src/events.js', '../point_src/automouse.js', '../point_src/distances.js', '../point_src/protractor.js', '../point_src/text/beta.js', '../point_src/dragging.js', '../point_src/functions/clamp.js', '../point_src/stage-hooks.js', '../point_src/functions/resolve.js', '../point_src/stage.js', '../point_src/cone.js', '../point_src/constrain-distance.js')
markdown {'html': '<p>A point cannot exceed the rotation around a point to a maxmium angle value,\nrelative to the origin point zero.</p>\n<p>Meaning if we have a point (origin), and another point (knee). The position\nof the knee may not lye outside a cone projected from the center of origin,</p>\n<p>Rotating the origin will slide the position around the origin center\nMoving the knee will <em>lock</em> at the edges of the projected cone.</p>\n<p>distance is handled by another element, and is optional here.</p>\n<p>This demo uses two constraints together:</p>\n<ol>\n<li><code>cone()</code> limits the angle of the child around its parent.</li>\n<li><code>track()</code> keeps the child at a fixed distance from its parent.</li>\n</ol>\n<p>So the cone decides <em>where the point may rotate</em>, while track decides <em>how far\naway it stays</em>. Combining them gives a simple joint with angular limits.</p>', 'content': '---\ntitle: Locked Joint\nfiles:\n ../point_src/core/head.js\n ../point_src/pointpen.js\n ../point_src/pointdraw.js\n ../point_src/pointlist.js\n ../point_src/point-content.js\n ../point_src/point.js\n ../point_src/events.js\n ../point_src/automouse.js\n ../point_src/distances.js\n ../point_src/dragging.js\n ../point_src/functions/clamp.js\n ../point_src/stage.js\n ../point_src/cone.js\n ../point_src/constrain-distance.js\n---\n\nA point cannot exceed the rotation around a point to a maxmium angle value,\nrelative to the origin point zero.\n\nMeaning if we have a point (origin), and another point (knee). The position\nof the knee may not lye outside a cone projected from the center of origin,\n\nRotating the origin will slide the position around the origin center\nMoving the knee will _lock_ at the edges of the projected cone.\n\ndistance is handled by another element, and is optional here.\n\nThis demo uses two constraints together:\n\n1. `cone()` limits the angle of the child around its parent.\n2. `track()` keeps the child at a fixed distance from its parent.\n\nSo the cone decides _where the point may rotate_, while track decides _how far\naway it stays_. Combining them gives a simple joint with angular limits.'}