math 相关问题

数学涉及在程序中操纵数字。有关一般数学问题,请咨询https://math.stackexchange.com/

计算svg圆形图表上每条路径的旋转角度

https://jsfiddle.net/p4d57e8x/3/ const getArcPath = (开始, 结束, 内半径, 外半径) => { const startAngle = 开始 * Math.PI * 2; const endAngle = 结束 * Math.PI * 2; 常量 x1 =

回答 1 投票 0

如何解决这个数学问题并将其转化为算法代码

https://drive.google.com/file/d/1fNt2PPM-ouTYrW55Ixksad_xeKZMdcLk/view?usp=sharing (抱歉,我还不能发布图像,所以我需要将其发布到我的驱动器中) 我在计算阴影面积时遇到了这个问题...

回答 1 投票 0

C++ - 指针上的运算符 -= [重复]

假设我有指针数组: char* buf = 新的 char[256]; 如果我这样做,数组指针的值/大小会发生什么 buf -= 100;

回答 2 投票 0

为什么在分解循环中除以相同的因子?

函数因子(余数){ var 因子 = [], i; 对于 (i = 2; i <= remainder; i++) { while ((remainder % i) === 0) { factors.push(i); remainder /= i; ...

回答 3 投票 0

为什么这个js代码函数要这样写?

函数因子(余数){ var 因子 = [], i; 对于 (i = 2; i <= remainder; i++) { while ((remainder % i) === 0) { factors.push(i); remainder /= i; ...

回答 1 投票 0

如何修复在矩阵 MIP 中查找最大值时出现的错误?

我坚持通过在 MIP 中编写约束来查找每列的最大值。不幸的是,错误是 错误 59 内生 prod smin smax 需要模型类型 错误 256 方程 eq2.. VAR prod smin smax

回答 1 投票 0

信用卡方程式(C# 语言)

我有一个作业问题需要验证。我得到了问题第一部分的正确答案。然而,问题的第二部分效果不太好。我不是...

回答 2 投票 0

Python:从一条二维线中减去另一条线

问题 我需要计算两条线之间的差异(即从另一条线中减去一条线),这应该会产生一条输出线。 输入线和输出线可能包括垂直线

回答 1 投票 0

算法:计算椭圆内的伪随机点

对于我正在制作的简单粒子系统,我需要给定一个具有宽度和高度的椭圆,计算位于该椭圆内的随机点 X, Y。 现在我的数学不是最好的,所以我想......

回答 5 投票 0

根据焦点和共同准线找到两个抛物线的交点 [Lua]

我有两条由各自焦点定义的抛物线((fx1,fy1)和(fx2,fy2)),以及一个公共准线dirY。 我需要找到这两个抛物线的交点,因为高度......

回答 1 投票 0

实现贝塞尔曲线的弧长参数化和自适应细分

我正在尝试以编程方式确定贝塞尔曲线的多个方面。我希望能够找到曲线的弧长,沿着曲线定位的点在...

回答 1 投票 0

给定的三个坐标可以是矩形的点吗

我目前正在学习如何用Python编写代码,我遇到了这个任务,我正在尝试解决它。但我认为我在某个地方犯了错误,我想知道也许有人可以帮助我。

回答 1 投票 0

在 c 中查找数组中位数时出现问题

我试图从c中的数据数组中找到中位数,但每次尝试时,即使数组中只有一个零,我也会得到零,数组在被插补之前已排序......

回答 1 投票 0

负指数的平方

我不确定平方幂是否可以处理负指数。我实现了以下代码,该代码仅适用于正数。 #包括 int power(int x, int exp...

回答 1 投票 0

求自己画的图形占图形面积的百分比

有简单形状(红色三角形)和复杂形状(黑色“U 形”)。 我用鼠标绘制蓝色形状并愿意找到:被绘图覆盖的图形的百分比(蓝色)。 有简单形状(红色三角形)和复杂形状(黑色“U 形”)。 我用鼠标绘制蓝色形状并愿意找到:被绘图覆盖的图形的百分比(蓝色)。 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Canvas</title> <style> canvas { border: 1px solid black; } </style> </head> <body> <canvas id="canvas" width="800" height="600"></canvas> <script> const canvas = document.getElementById("canvas"); const ctx = canvas.getContext("2d"); const radius = 15; const random_shape = [ { x: 20, y: 20, width: 20, height: 100 }, { x: 60, y: 20, width: 20, height: 100 }, { x: 20, y: 120, width: 60, height: 20 }, ]; const triangle = [ { x: 200, y: 400 }, { x: 400, y: 200 }, { x: 600, y: 400 }, ]; let isDrawing = false; let lastX = 0; let lastY = 0; let pixelsInsideFigure = 0; function draw_random_shape() { for (let i = 0; i < random_shape.length; i++) { ctx.fillStyle = "black"; ctx.fillRect( random_shape[i].x, random_shape[i].y, random_shape[i].width, random_shape[i].height ); } } function draw_triangle() { ctx.beginPath(); ctx.moveTo(triangle[0].x, triangle[0].y); for (let i = 1; i < triangle.length; i++) { ctx.lineTo(triangle[i].x, triangle[i].y); } ctx.closePath(); ctx.fillStyle = "red"; ctx.fill(); } function handleMouseDown(e) { isDrawing = true; [lastX, lastY] = [e.offsetX, e.offsetY]; if (pointInShape({ x: lastX, y: lastY }, random_shape)) { pixelsInsideFigure++; } } function handleMouseMove(e) { if (!isDrawing) return; ctx.strokeStyle = "blue"; ctx.lineJoin = "round"; ctx.lineCap = "round"; ctx.lineWidth = radius; ctx.beginPath(); ctx.moveTo(lastX, lastY); ctx.lineTo(e.offsetX, e.offsetY); ctx.stroke(); [lastX, lastY] = [e.offsetX, e.offsetY]; if (pointInShape({ x: lastX, y: lastY }, random_shape)) { pixelsInsideFigure++; } } function handleMouseUp() { isDrawing = false; calculatePercentage(); pixelsInsideFigure = 0; } function clearUserInput() { ctx.clearRect(0, 0, canvas.width, canvas.height); draw_triangle(); draw_random_shape(); } function calculatePercentage() { const coveredArea = calculateCoveredArea( { x: lastX, y: lastY }, radius ); const totalArea = Math.PI * Math.pow(radius, 2); const coveragePercentage = (coveredArea / totalArea) * 100; alert(`Area Coverage Percentage: ${coveragePercentage.toFixed(2)}%`); clearUserInput(); } function pointInShape(point, vertices) { let inside = false; const x = point.x; const y = point.y; for (let i = 0, j = vertices.length - 1; i < vertices.length; j = i++) { const xi = vertices[i].x; const yi = vertices[i].y; const xj = vertices[j].x; const yj = vertices[j].y; const intersect = yi > y != yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi; if (intersect) inside = !inside; } return inside; } function calculateCoveredArea(point, radius) { let coveredArea = 0; const centerX = point.x; const centerY = point.y; for (let x = centerX - radius; x <= centerX + radius; x++) { for (let y = centerY - radius; y <= centerY + radius; y++) { const distance = Math.sqrt( Math.pow(x - centerX, 2) + Math.pow(y - centerY, 2) ); if (distance <= radius) { if (pointInShape({ x: x, y: y }, random_shape)) { console.log("INSIDE RANDOM SHAPE"); coveredArea++; } if (pointInShape({ x: x, y: y }, triangle)) { console.log("INSIDE Triangle"); coveredArea++; } } } } return coveredArea; } function calculateArea(vertices) { let area = 0; for (let i = 0, j = vertices.length - 1; i < vertices.length; j = i++) { area += (vertices[j].x + vertices[i].x) * (vertices[j].y - vertices[i].y); } return Math.abs(area / 2); } function init() { draw_triangle(); draw_random_shape(); canvas.addEventListener("mousedown", handleMouseDown); canvas.addEventListener("mousemove", handleMouseMove); canvas.addEventListener("mouseup", handleMouseUp); } init(); </script> </body> </html> 附注作为《哈利·波特 1》中的参考,我必须引导一根魔杖来适应形状。要通过技能,您必须正确覆盖该区域。 在提供的情况下,我预计能达到 60-70% 左右(左上角)。 在互联网上搜索,询问“机器人”,进行数学调整 - 没有帮助。 期望:计算和查找面积百分比的正确方法。 我首先想到的是,您可以计算用户绘制后显示的总像素,然后您可以与目标形状像素数进行比较。只是一个想法

回答 1 投票 0

特定位运算CPU中的运算次数

对于仅进行位运算(位加、位乘、位或等)的 CPU,需要多少位运算才能计算 x + y、x.y 和 x mod y,其中 x 是 m -位长,y 为 n 位长...

回答 1 投票 0

如何在markdown中的扰流块中添加数学表达式

我想在剧透块中包含数学表达式,实际上是 github 存储库的 markdown 中的详细信息/摘要块。当我尝试在块中使用 $$ 来使用数学语法时,数学表达式...

回答 1 投票 0

计算树中所有奇数路径

我的任务是,给定一个非循环非直接图,计算由奇数条边连接的节点对。 我的问题是为什么我应该从那些具有...的顶点开始搜索图表?

回答 1 投票 0

将 FqFieldElem 转换为整数

我是 Julia 的初学者,我正在使用 Nemo 库在有限域上做一些事情。 我想计算给定有限域的特征,为此我必须计算数量

回答 1 投票 0

在 Three.js 中仅提取复杂 BufferGeometry 的外部边缘

我目前正在开发一个涉及使用 Three.js 进行区域创建和碰撞检测的项目,其中我的应用程序可以正确处理碰撞并生成 BufferGeometry 作为结果。我...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.