intersects icon indicating copy to clipboard operation
intersects copied to clipboard

Hey I still that TangJin i am living taiwan,if u can type chinese just do it

Open tangjin0418 opened this issue 4 years ago • 19 comments

i am making a game it need angle,i see ur comment of that,oval angle is require maybe u can give me other package or something i think rx and ry cant change the angle rotate maybe it easy maybe it hard i need a correct anwser of that

tangjin0418 avatar Feb 28 '21 04:02 tangjin0418

and i do something on codepen like if oval r is 60 and 75 it spin 90 angle it value will change to r 75 60 so i think it possible to calc

tangjin0418 avatar Feb 28 '21 04:02 tangjin0418

`

function initialize() { innerPolygonCoef = [] outerPolygonCoef = [] for (var t = 0; t <= MAX_ITERATIONS; t++) { var numNodes = 4 << t innerPolygonCoef[t] = 0.5 / Math.cos(4 * Math.acos(0) / numNodes) outerPolygonCoef[t] = 0.5 / (Math.cos(2 * Math.acos(0) / numNodes) * Math.cos(2 * Math.acos(0) / numNodes)) } initialized = true }

function iterate(x, y, c0x, c0y, c2x, c2y, rr) { for (var t = 1; t <= MAX_ITERATIONS; t++) { var c1x = (c0x + c2x) * innerPolygonCoef[t] var c1y = (c0y + c2y) * innerPolygonCoef[t] var tx = x - c1x var ty = y - c1y if (tx * tx + ty * ty <= rr) { return true } var t2x = c2x - c1x var t2y = c2y - c1y if (tx * t2x + ty * t2y >= 0 && tx * t2x + ty * t2y <= t2x * t2x + t2y * t2y && (ty * t2x - tx * t2y >= 0 || rr * (t2x * t2x + t2y * t2y) >= (ty * t2x - tx * t2y) * (ty * t2x - tx * t2y))) { return true } var t0x = c0x - c1x var t0y = c0y - c1y if (tx * t0x + ty * t0y >= 0 && tx * t0x + ty * t0y <= t0x * t0x + t0y * t0y && (ty * t0x - tx * t0y <= 0 || rr * (t0x * t0x + t0y * t0y) >= (ty * t0x - tx * t0y) * (ty * t0x - tx * t0y))) { return true } var c3x = (c0x + c1x) * outerPolygonCoef[t] var c3y = (c0y + c1y) * outerPolygonCoef[t] if ((c3x - x) * (c3x - x) + (c3y - y) * (c3y - y) < rr) { c2x = c1x c2y = c1y continue } var c4x = c1x - c3x + c1x var c4y = c1y - c3y + c1y if ((c4x - x) * (c4x - x) + (c4y - y) * (c4y - y) < rr) { c0x = c1x c0y = c1y continue } var t3x = c3x - c1x var t3y = c3y - c1y if (ty * t3x - tx * t3y <= 0 || rr * (t3x * t3x + t3y * t3y) > (ty * t3x - tx * t3y) * (ty * t3x - tx * t3y)) { if (tx * t3x + ty * t3y > 0) { if (Math.abs(tx * t3x + ty * t3y) <= t3x * t3x + t3y * t3y || (x - c3x) * (c0x - c3x) + (y - c3y) * (c0y - c3y) >= 0) { c2x = c1x c2y = c1y continue } } else if (-(tx * t3x + ty * t3y) <= t3x * t3x + t3y * t3y || (x - c4x) * (c2x - c4x) + (y - c4y) * (c2y - c4y) >= 0) { c0x = c1x c0y = c1y continue } } return false } return false // Out of iterations so it is unsure if there was a collision. But have to return something. }

// Test for collision between an ellipse of horizontal radius w0 and vertical radius h0 at (x0, y0) and // an ellipse of horizontal radius w1 and vertical radius h1 at (x1, y1) function ellipseEllipse(x0, y0, w0, h0, x1, y1, w1, h1) { if (!initialized) { initialize() }

var x = Math.abs(x1 - x0) * h1
var y = Math.abs(y1 - y0) * w1
w0 *= h1
h0 *= w1
var r = w1 * h1

if (x * x + (h0 - y) * (h0 - y) <= r * r || (w0 - x) * (w0 - x) + y * y <= r * r || x * h0 + y * w0 <= w0 * h0
    || ((x * h0 + y * w0 - w0 * h0) * (x * h0 + y * w0 - w0 * h0) <= r * r * (w0 * w0 + h0 * h0) && x * w0 - y * h0 >= -h0 * h0 && x * w0 - y * h0 <= w0 * w0))
{
    return true
}
else
{
    if ((x - w0) * (x - w0) + (y - h0) * (y - h0) <= r * r || (x <= w0 && y - r <= h0) || (y <= h0 && x - r <= w0))
    {
        return iterate(x, y, w0, 0, 0, h0, r * r)
    }
    return false
}

}

// Test for collision between an ellipse of horizontal radius w and vertical radius h at (x0, y0) and // a circle of radius r at (x1, y1) function ellipseCircle(x0, y0, w, h, x1, y1, r) { if (!initialized) { initialize() } var x = Math.abs(x1 - x0) var y = Math.abs(y1 - y0)

if (x * x + (h - y) * (h - y) <= r * r || (w - x) * (w - x) + y * y <= r * r || x * h + y * w <= w * h
    || ((x * h + y * w - w * h) * (x * h + y * w - w * h) <= r * r * (w * w + h * h) && x * w - y * h >= -h * h && x * w - y * h <= w * w))
{
    return true
}
else
{
    if ((x - w) * (x - w) + (y - h) * (y - h) <= r * r || (x <= w && y - r <= h) || (y <= h && x - r <= w))
    {
        return iterate(x, y, w, 0, 0, h, r * r)
    }
    return false
}

} `

`var ctx = document.getElementById("x").getContext("2d");

document.getElementById("x").addEventListener("mousemove", (e) => { ctx.clearRect(0, 0, 1000, 500); var x = e.clientX, y = e.clientY; ctx.beginPath(); ctx.ellipse(100, 100, 50, 75, Math.PI / 2, 0, 2 * Math.PI); ctx.stroke(); ctx.closePath();

ctx.beginPath(); ctx.arc(x, y, 35, 0, 3.14*2); ctx.stroke(); ctx.closePath(); if(ellipseCircle(100,100,75,50,x,y,35)){ ctx.fillStyle="red" }else{ ctx.fillStyle="green" } ctx.fill() }); `

tangjin0418 avatar Feb 28 '21 04:02 tangjin0418

Do you have the codepen link?

davidfig avatar Feb 28 '21 04:02 davidfig

umm does github have dm?

tangjin0418 avatar Feb 28 '21 05:02 tangjin0418

i think we can code with glitch

tangjin0418 avatar Feb 28 '21 05:02 tangjin0418

give me glitch name

tangjin0418 avatar Feb 28 '21 05:02 tangjin0418

@davidfig

davidfig avatar Feb 28 '21 05:02 davidfig

u sure?

tangjin0418 avatar Feb 28 '21 05:02 tangjin0418

image

tangjin0418 avatar Feb 28 '21 05:02 tangjin0418

try again. i just signed up moments ago

davidfig avatar Feb 28 '21 05:02 davidfig

ok

tangjin0418 avatar Feb 28 '21 05:02 tangjin0418

it still none can u friend me? @hitangjin

tangjin0418 avatar Feb 28 '21 05:02 tangjin0418

i don't see any friend list, just collaborators for projects. here's my id: Screen Shot 2021-02-28 at 1 37 29 PM

It may take time to propagate.

davidfig avatar Feb 28 '21 05:02 davidfig

hey u search @hitangjin

tangjin0418 avatar Feb 28 '21 05:02 tangjin0418

and click a avater like rainbow

tangjin0418 avatar Feb 28 '21 05:02 tangjin0418

I tried that. It's not clickable. Maybe you have to upgrade or something?

davidfig avatar Feb 28 '21 05:02 davidfig

ok wait

tangjin0418 avatar Feb 28 '21 05:02 tangjin0418

https://glitch.com/edit/#!/rounded-bedecked-slime

tangjin0418 avatar Feb 28 '21 05:02 tangjin0418

do u see me?i am at script.js line one

tangjin0418 avatar Feb 28 '21 05:02 tangjin0418