Hello! So, I've been picking up JS pretty easily. I've been able to learn quickly, and figuring out the logic is pretty intuitive to me. But sometimes, what I want to do involves...
...math 😢
I've found coding to be more like literature than mathematics TBH, with the way my brain processes it at least. I've gotten by so far with my basic AF math skills, but I've just now gotten stuck and have no idea how to even begin approaching this:
This is part of a plugin. I just want to check whether a coordinate point (in screen pixels) is within range of another point (and if so, then push some values into a couple arrays). I've had it working just fine for a while with the basic circle and square range/area shapes, but I've just added the option to make elongated ranges/areas (i.e. ovals and rectangles) by setting separate radius values for the X and Y axes.
But, uh... now I don't know how to mathematically implement the oval one. Or where to even begin - my brain just short circuits when I try to start conceptualizing it, because mAtH hArD. Help please? 😅
This is what I've got so far of the specific portion of code I'm working with (this is part of a larger function, so there's more before and after it that isn't immediately relevant to this math problem):
Thank you for any and all pointers!!
...math 😢
I've found coding to be more like literature than mathematics TBH, with the way my brain processes it at least. I've gotten by so far with my basic AF math skills, but I've just now gotten stuck and have no idea how to even begin approaching this:
This is part of a plugin. I just want to check whether a coordinate point (in screen pixels) is within range of another point (and if so, then push some values into a couple arrays). I've had it working just fine for a while with the basic circle and square range/area shapes, but I've just added the option to make elongated ranges/areas (i.e. ovals and rectangles) by setting separate radius values for the X and Y axes.
But, uh... now I don't know how to mathematically implement the oval one. Or where to even begin - my brain just short circuits when I try to start conceptualizing it, because mAtH hArD. Help please? 😅
This is what I've got so far of the specific portion of code I'm working with (this is part of a larger function, so there's more before and after it that isn't immediately relevant to this math problem):
JavaScript:
var distanceX = Math.abs((TouchInput.x + offsetX) - ($gameMap.event(eventId).screenX() + originX));
var distanceY = Math.abs((TouchInput.y + offsetY) - ($gameMap.event(eventId).screenY() + originY));
let distanceDirect = Math.sqrt((distanceX * distanceX) + (distanceY * distanceY));
if (shape == 'Circle') {
if (radiusX == radiusY) {
// This is basically what I had before I split the radius parameter into radiusX and radiusY
if (distanceDirect <= radiusX) {
nearbyIds.push(parseInt(eventId));
allDistances.push(distanceDirect);
}
} else {
// ????????????????????????????????????????????
// This is where I don't know what to do (when radiusX and radiusY are different) to simulate an oval-shaped range
}
} else if (shape == 'Square') {
if (distanceX <= radiusX && distanceY <= radiusY) {
nearbyIds.push(parseInt(eventId));
allDistances.push(distanceDirect);
}
}
Thank you for any and all pointers!!