Skip to content

Commit

Permalink
physics constants match han paper
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Oct 18, 2023
1 parent 86dbef5 commit 99a4d86
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 76 deletions.
2 changes: 1 addition & 1 deletion dist/diagram.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/diagrams/diagrams.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ body {

.child {
position: absolute;
top: 0;
top: 32px;
left: 0;
}

Expand Down
2 changes: 1 addition & 1 deletion dist/diagrams/diagrams.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<div class="replaydiagram">
<div
class="topview"
data-state="?ruletype=threecushion&state=%7B%22init%22:%5B-0.76875,-0.1921875,-0.76875,0,0.76875,0%5D,%22shots%22:%5B%7B%22type%22:%22AIM%22,%22offset%22:%7B%22x%22:-0.219,%22y%22:0.156,%22z%22:0%7D,%22angle%22:0.146,%22power%22:3.026,%22pos%22:%7B%22x%22:-0.76875,%22y%22:-0.1921875,%22z%22:0%7D,%22i%22:0%7D%5D%7D"
data-state="?ruletype=threecushion&state=%7B%22init%22%3A%5B-0.76875%2C-0.1921875%2C-0.76875%2C0%2C0.76875%2C0%5D%2C%22shots%22%3A%5B%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.131%2C%22y%22%3A0.155%2C%22z%22%3A0%7D%2C%22angle%22%3A0.146%2C%22power%22%3A3.046%2C%22pos%22%3A%7B%22x%22%3A-0.76875%2C%22y%22%3A-0.1921875%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%5D%7D"
></div>
<p class="description">break off shot</p>
</div>
Expand Down
14 changes: 8 additions & 6 deletions dist/diagrams/diamond.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,22 @@
<div class="replaydiagram child">
<div
class="topview"
data-state="?ruletype=threecushion&state=%7B%22init%22%3A%5B-1.377%2C-0.717%2C-0.769%2C0%2C0.769%2C0%5D%2C%22shots%22%3A%5B%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.3%2C%22y%22%3A0%2C%22z%22%3A0%7D%2C%22angle%22%3A0.731%2C%22power%22%3A2%2C%22pos%22%3A%7B%22x%22%3A-1.377%2C%22y%22%3A-0.717%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%5D%7D"
data-state="?ruletype=threecushion&state=%7B%22init%22%3A%5B-1.489%2C-0.763%2C-1.4330625000000001%2C0%2C-1.4330625000000001%2C-0.09825%5D%2C%22shots%22%3A%5B%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.35%2C%22y%22%3A0%2C%22z%22%3A0%7D%2C%22angle%22%3A0.717%2C%22power%22%3A2.6%2C%22pos%22%3A%7B%22x%22%3A-1.489%2C%22y%22%3A-0.763%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%5D%7D"
></div>
</div>

<div class="replaydiagram child">
<div
class="topview"
data-state="?ruletype=threecushion&state=%7B%22init%22%3A%5B-0.625%2C-0.7%2C-0.769%2C0%2C0.769%2C0%5D%2C%22shots%22%3A%5B%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.3%2C%22y%22%3A0%2C%22z%22%3A0%7D%2C%22angle%22%3A0.842%2C%22power%22%3A2%2C%22pos%22%3A%7B%22x%22%3A-0.625%2C%22y%22%3A-0.7%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%5D%7D"
data-state="?ruletype=threecushion&state=%7B%22init%22%3A%5B-0.686%2C-0.748%2C-1.4330625000000001%2C0%2C-1.4330625000000001%2C-0.09825%5D%2C%22shots%22%3A%5B%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.35%2C%22y%22%3A0%2C%22z%22%3A0%7D%2C%22angle%22%3A0.828%2C%22power%22%3A2.6%2C%22pos%22%3A%7B%22x%22%3A-0.686%2C%22y%22%3A-0.748%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%5D%7D"
></div>
</div>

<div class="replaydiagram child">
<div
class="topview"
data-state="?ruletype=threecushion&state=%7B%22init%22%3A%5B0.12%2C-0.682%2C-0.769%2C0%2C0.769%2C0%5D%2C%22shots%22%3A%5B%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.3%2C%22y%22%3A0%2C%22z%22%3A0%7D%2C%22angle%22%3A0.981%2C%22power%22%3A2%2C%22pos%22%3A%7B%22x%22%3A0.12%2C%22y%22%3A-0.682%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%5D%7D"
data-state="?ruletype=threecushion&state=%7B%22init%22%3A%5B0.111%2C-0.731%2C-1.4330625000000001%2C0%2C-1.4330625000000001%2C-0.09825%5D%2C%22shots%22%3A%5B%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.35%2C%22y%22%3A0%2C%22z%22%3A0%7D%2C%22angle%22%3A0.968%2C%22power%22%3A2.6%2C%22pos%22%3A%7B%22x%22%3A0.111%2C%22y%22%3A-0.731%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%5D%7D"
></div>
</div>
</div>

<div class="diagram">
<iframe
width="400"
Expand Down Expand Up @@ -66,6 +63,11 @@
<label for="rho">rho</label>
</div>

<div class="diagram">
<p>Diamond system should match standard table outcome.</p>
<p id="common"></p>
</div>

<script src="../vendor.js"></script>
<script src="../diagram.js"></script>
</body>
Expand Down
18 changes: 1 addition & 17 deletions dist/diagrams/nineball.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,7 @@
<div class="replaydiagram">
<div
class="topview"
data-state="?ruletype=nineball&state=%7B%22init%22:%5B0.9791627774741956,-0.16712768274724346,-0.1939629326120725,-0.21500987166981342,1.3885871723848404,0.7288381689112076,0.8668492910935701,-0.15896745034377294,0.7902212948322053,0.009735382705431195,1.3804008618527324,-0.7314072289431331,0.47711787610264283,-0.5764539778418994,1.0866310387372964,0.18741224854979702,0.5939860463659818,-0.5142514865262328,1.3405179202096094,0.709637794034107%5D,%22shots%22:%5B%7B%22type%22:%22AIM%22,%22offset%22:%7B%22x%22:-0.161,%22y%22:-0.253,%22z%22:0%7D,%22angle%22:1.314,%22power%22:3.69,%22pos%22:%7B%22x%22:0.9791627774741956,%22y%22:-0.16712768274724346,%22z%22:0%7D,%22i%22:0%7D%5D%7D"
></div>
<p class="description">pool but balls hold spin like three cushion</p>
</div>

<div class="replaydiagram">
<div
class="topview"
data-state="?ruletype=nineball&state=%7B%22init%22:%5B0.041765375448265626,0.16673084874926705,-0.06866529693808243,-0.17794139097729444,0.6661551985587442,0.12787874192705445,0.7144579556527048,-0.052262243925261735,0.778,0,1.391618559770696,-0.7122033618446454,1.3620819291511166,0.7279283685799462,0.7622939841156352,0.4082866046785468,1.2664360630397673,-0.21084090715648798,0.5924478372442701,-0.5170753942107428%5D,%22shots%22:%5B%7B%22type%22:%22AIM%22,%22offset%22:%7B%22x%22:-0.193,%22y%22:-0.229,%22z%22:0%7D,%22angle%22:-1.974,%22power%22:2.583,%22pos%22:%7B%22x%22:0.041765375448265626,%22y%22:0.16673084874926705,%22z%22:0%7D,%22i%22:0%7D%5D%7D"
></div>
<p class="description">screw and side</p>
</div>

<div class="replaydiagram">
<div
class="topview"
data-state="?ruletype=nineball&state=%7B%22init%22%3A%5B-0.6765%2C0%2C0.66%2C0%2C0.72%2C0.035%2C0.72%2C-0.034%2C0.777%2C0.001%2C0.78%2C-0.068%2C0.779%2C0.067%2C0.838%2C0.034%2C0.838%2C-0.034%2C0.894%2C0.001%5D%2C%22shots%22%3A%5B%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A0.014%2C%22y%22%3A-0.113%2C%22z%22%3A0%7D%2C%22angle%22%3A0%2C%22power%22%3A4.613%2C%22pos%22%3A%7B%22x%22%3A-0.6765%2C%22y%22%3A0%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%2C%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A0.014%2C%22y%22%3A-0.113%2C%22z%22%3A0%7D%2C%22angle%22%3A1.188%2C%22power%22%3A4.613%2C%22pos%22%3A%7B%22x%22%3A-0.030299100884650404%2C%22y%22%3A0.10788257915305026%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%2C%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A0.032%2C%22y%22%3A0.203%2C%22z%22%3A0%7D%2C%22angle%22%3A0.882%2C%22power%22%3A2.768%2C%22pos%22%3A%7B%22x%22%3A0.5777159138326813%2C%22y%22%3A-0.642270976985548%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%2C%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A0.014%2C%22y%22%3A-0.149%2C%22z%22%3A0%7D%2C%22angle%22%3A0.216%2C%22power%22%3A2.306%2C%22pos%22%3A%7B%22x%22%3A-0.4477698018582841%2C%22y%22%3A0.449039868522194%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%2C%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.055%2C%22y%22%3A0.295%2C%22z%22%3A0%7D%2C%22angle%22%3A-0.028%2C%22power%22%3A2.306%2C%22pos%22%3A%7B%22x%22%3A0.31344265637968144%2C%22y%22%3A0.49652648764457624%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%2C%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A0.014%2C%22y%22%3A-0.203%2C%22z%22%3A0%7D%2C%22angle%22%3A2.656%2C%22power%22%3A2.306%2C%22pos%22%3A%7B%22x%22%3A0.2061980591052964%2C%22y%22%3A-0.34039677282025305%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%2C%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.194%2C%22y%22%3A0.14%2C%22z%22%3A0%7D%2C%22angle%22%3A2.028%2C%22power%22%3A3.69%2C%22pos%22%3A%7B%22x%22%3A-0.803477680880146%2C%22y%22%3A-0.22912438115761186%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%2C%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.194%2C%22y%22%3A0.14%2C%22z%22%3A0%7D%2C%22angle%22%3A2.414%2C%22power%22%3A3.69%2C%22pos%22%3A%7B%22x%22%3A1.0077340998903348%2C%22y%22%3A-0.5763352400546439%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%5D%7D"
data-state="?ruletype=nineball&state=%7B%22init%22%3A%5B-0.7205%2C0%2C0.703%2C-0.001%2C0.767%2C0.035%2C0.767%2C-0.037%2C0.828%2C-0.001%2C0.828%2C-0.072%2C0.829%2C0.073%2C0.891%2C0.035%2C0.891%2C-0.035%2C0.953%2C0.001%5D%2C%22shots%22%3A%5B%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A0.012%2C%22y%22%3A-0.155%2C%22z%22%3A0%7D%2C%22angle%22%3A0%2C%22power%22%3A3.93%2C%22pos%22%3A%7B%22x%22%3A-0.7205%2C%22y%22%3A0%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%2C%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.155%2C%22y%22%3A-0.155%2C%22z%22%3A0%7D%2C%22angle%22%3A0.396%2C%22power%22%3A3.93%2C%22pos%22%3A%7B%22x%22%3A0.43853827510125376%2C%22y%22%3A0.05428281958989272%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%2C%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.024%2C%22y%22%3A-0.19%2C%22z%22%3A0%7D%2C%22angle%22%3A-0.227%2C%22power%22%3A4.913%2C%22pos%22%3A%7B%22x%22%3A-0.7929277136460852%2C%22y%22%3A0.34108862659315176%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%2C%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.024%2C%22y%22%3A-0.19%2C%22z%22%3A0%7D%2C%22angle%22%3A-1.354%2C%22power%22%3A4.913%2C%22pos%22%3A%7B%22x%22%3A1.1962772774979158%2C%22y%22%3A0.30157380947378504%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%2C%7B%22type%22%3A%22AIM%22%2C%22offset%22%3A%7B%22x%22%3A-0.024%2C%22y%22%3A-0.19%2C%22z%22%3A0%7D%2C%22angle%22%3A-2.635%2C%22power%22%3A4.913%2C%22pos%22%3A%7B%22x%22%3A1.0110588283030948%2C%22y%22%3A-0.16418849937464705%2C%22z%22%3A0%7D%2C%22i%22%3A0%7D%5D%7D"
></div>
<p class="description">a break</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion dist/diagrams/odd.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<div class="replaydiagram">
<div
class="topview"
data-state="?ruletype=threecushion&state=%7B%22init%22:%5B-0.769,-0.192,0.769,0,1.07,0%5D,%22shots%22:%5B%7B%22type%22:%22AIM%22,%22offset%22:%7B%22x%22:-0.202,%22y%22:0.222,%22z%22:0%7D,%22angle%22:-0.77,%22power%22:2.694,%22pos%22:%7B%22x%22:-0.769,%22y%22:-0.192,%22z%22:0%7D,%22i%22:0%7D%5D%7D"
data-state="?ruletype=threecushion&state=%7B%22init%22:%5B-0.769,-0.192,0.769,0,1.07,0%5D,%22shots%22:%5B%7B%22type%22:%22AIM%22,%22offset%22:%7B%22x%22:-0.202,%22y%22:0.222,%22z%22:0%7D,%22angle%22:-0.77,%22power%22:3.0,%22pos%22:%7B%22x%22:-0.769,%22y%22:-0.192,%22z%22:0%7D,%22i%22:0%7D%5D%7D"
></div>
<p class="description">
reverse side off first cushion should slip and retain the spin. Blend
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"@testing-library/dom": "^9.3.3",
"@types/chai": "^4.3.9",
"@types/jest": "^29.5.6",
"@types/node": "^20.8.6",
"@types/three": "^0.157.0",
"@types/node": "^20.8.7",
"@types/three": "^0.157.1",
"chai": "^4.3.10",
"ini": "^4.1.1",
"jest": "^29.7.0",
Expand Down
2 changes: 2 additions & 0 deletions src/diagram/diagramcontainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ export class DiagramContainer {
const stateUrl = containerDiv?.getAttribute("data-state")
const params = new URLSearchParams(stateUrl)
const p = diagram?.getElementsByClassName("description")[0]
const common = document.getElementById("common")
const editlink = document.createElement("a")
editlink.href = `../${stateUrl}`
editlink.innerHTML = "⬀"
editlink.target = "_blank"
p?.appendChild(editlink)
common?.appendChild(editlink)
const replaybutton = document.createElement("button")
p?.appendChild(replaybutton)
const diagramcontainer = new DiagramContainer(
Expand Down
6 changes: 3 additions & 3 deletions src/model/physics/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ export const g = 9.8
export let mu = 0.00985
export let muS = 0.105
export let muC = 0.8
export let rho = 0.025
export let m = 0.22
export let R = 0.03075
export let rho = 0.024
export let m = 0.23
export let R = 0.03275
export let e = 0.86
export let Mz: number
export let Mxy: number
Expand Down
2 changes: 1 addition & 1 deletion src/model/physics/physics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function rotateApplyUnrotate(theta, v, w, model) {

// cushion contact point epsilon above ball centre

const epsilon = R * 0.2
const epsilon = R * 0.1
const theta_a = Math.asin(epsilon / R)

const sin_a = Math.sin(theta_a)
Expand Down
22 changes: 15 additions & 7 deletions test/gen/diamon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("Controller", () => {
let broadcastEvents: GameEvent[]
let stepx: number
let stepy: number
const replayUrl = "http://localhost:8080/?ruletype=threecushion&state="
const replayUrl = "?ruletype=threecushion&state="
beforeEach(function (done) {
container = new Container(
document.getElementById("viewP1"),
Expand All @@ -39,16 +39,19 @@ describe("Controller", () => {
container.broadcast = (x) => broadcastEvents.push(x)
stepx = TableGeometry.X / 4
stepy = TableGeometry.Y / 2
container.table.balls[1].pos.x -= 1.5 * stepx
container.table.balls[2].pos.x = container.table.balls[1].pos.x
container.table.balls[2].pos.y -= 3 * R
done()
})

const toLowerRail = new Vector3(0, -3 * R)
const toUpperRail = new Vector3(0, 3 * R)
const toLowerRail = new Vector3(0, -2.25 * R)
const toUpperRail = new Vector3(0, 2.25 * R)

it("initialise ball for diamond system shot", (done) => {
expect(container.controller).to.be.an.instanceof(Init)
container.table.cue.aim.power = 2
container.table.cue.aim.offset.x = -0.3
container.table.cue.aim.power = 2.6
container.table.cue.aim.offset.x = -0.35
shot(gridPosition(0, 0), gridPosition(5, 4))
shot(gridPosition(2, 0), gridPosition(6, 4))
shot(gridPosition(4, 0), gridPosition(7, 4))
Expand All @@ -60,12 +63,12 @@ describe("Controller", () => {
const start = fromDiamond.add(toLowerRail)
const target = toDiamond.add(toUpperRail)
playAlong(start, target)
console.log(getURL())
console.log(diagramHTML(getURL()))
}

function playAlong(start, target) {
const dir = norm(target.clone().sub(start))
const ballStart = start.clone().addScaledVector(dir, R * 7)
const ballStart = start.clone().addScaledVector(dir, R * 6)
container.table.cueball.pos.copy(ballStart)
container.table.cue.aim.angle = round(Math.atan2(dir.y, dir.x))
}
Expand All @@ -85,4 +88,9 @@ describe("Controller", () => {
const shotUri = `${replayUrl}${encodeURIComponent(JSON.stringify(state))}`
return shotUri
}

function diagramHTML(uri) {
return `<div class="replaydiagram child"><div class="topview"
data-state="${uri}"></div></div>`
}
})
Loading

0 comments on commit 99a4d86

Please sign in to comment.