总是阻碍我做3D编程的一件事是无法理解数学是如何工作的.我可以使用方法和函数在编程流程中使用数学,然后它对我来说都是清晰和合乎逻辑的,但在数学符号中,我无法从它做出正面或反面.
我一直在阅读网站,观看研究所试图解释这个问题的视频,但他们都使用数学符号,我只是迷失在其中,我的思想不会将其转化为可理解的东西.我可能有缺陷.
另外,只是使用某人的代码不是我的兴趣,我想了解它背后的机制,逻辑.我很乐意使用其他人的代码,但我真的想了解它是如何工作的.
这个问题
你能用简单的术语向我解释没有数学符号,只是编程符号/函数/伪代码,如何沿所有3轴实现矩阵变换?
理想情况下我想要的是编写方法/对象的材料/理解,我可以在其中定义3个轴的角度,类似于glRotate,以旋转我所拥有的四边形/三角形的集合.(我正在尝试编写立方体形状的3D旋转而无需访问OpenGL函数来为我执行此操作,因为每次在显示列表中发生更改时,都会在一次绘制调用中完成.)
我做了什么?
我试图制作一个90度的变换函数来获得数学的悬念,但是在制作一个理论上最简单的矩阵时却完全失败了.你可以在http://jsfiddle.net/bLfg0tj8/5/看到我失败的尝试.
Vec3 = function(x,y,z) {
this.x = x;
this.y = y;
this.z = z;
}
Matrix = function Matrix() {
this.matrixPoints = new Array();
this.rotationPoint = new Vec3(0,0,0);
this.rotationAngle = 90;
}
Matrix.prototype.addVector = function(vector) {
this.matrixPoints.push(vector);
}
Matrix.prototype.setRotationPoint = function(vector) {
this.rotationPoint = vector;
}
Matrix.prototype.setRotationAngle = function(angle) {
this.rotationAngle = angle;
}
Matrix.prototype.populate = function() {
translateToOrigin = [[1,0,0-this.rotationPoint.x],
[0,1,0-this.rotationPoint.y],
[0,0,0-this.rotationPoint.z]];
rotationMatrix = [[0,-1,0],
[0,1,0],
[0,0,1]];
translateEnd …Run Code Online (Sandbox Code Playgroud)在适用于Android的OpenGL ES 1中,我有一个Rubic多维数据集,其中包含27个较小的多维数据集。我想要旋转,使特定的小立方体正好位于视点的前面。所以我需要两个向量 一个是从对象原点到特定立方体的向量。另一个是从原点到视点的向量。然后它们的叉积给我旋转轴,点积给我角度。
我将(0,0,1)(这是从原点到世界坐标中的视点的向量)转换为对象坐标。这是代码:
matrixGrabber.getCurrentModelView(gl);
temporaryMatrix.set(matrixGrabber.mModelView);
inputVector[0] = 0f;
inputVector[1] = 0f;
inputVector[2] = 1f;
inputVector[3] = 1f;
Matrix.multiplyMV(resultVector, 0, temporaryMatrix.InvertMatrix(), 0, inputVector,0);
resultVector[0]/=resultVector[3];
resultVector[1]/=resultVector[3];
resultVector[2]/=resultVector[3];
inputVector = ..... // appropriate vector due to user-selection
axis = Vector.normalized(Vector.crossProduct(Vector.normalized(inputVector), Vector.normalized(resultVector)));
degree = (float)Math.toDegrees(Math.acos(Vector.dot(Vector.normalized(inputVector), Vector.normalized(resultVector))));
Run Code Online (Sandbox Code Playgroud)
我使用两个四元数进行旋转。每次用户选择一个动作时,都会发生一种轮换。这是代码:
Quaternion currentRotation = new Quaternion();
Quaternion temporaryRotation = new Quaternion();
.
.
.
currentRotation = (currentRotation).mulLeft(temporaryRotation.set(axis, degree));
currentRotation.toMatrix(matrix);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glMultMatrixf(matrix, 0);
Run Code Online (Sandbox Code Playgroud)
现在的问题是,它在第一次旋转时效果很好。不管第一次旋转。它运作良好,但是对于下一个旋转,它似乎得到了错误的轴和度。
例如,如果坐标系为
然后首先绕逆时针(CCW)旋转X 90度产生
第二次绕Z 90度逆时针旋转产生
在 Pygame 中,如何计算箭头的三个点的坐标,给定箭头的起点和终点,使箭头指向与线相同的方向?
def __draw_arrow(self, screen, colour, start, end):
start = self.__coordinate_lookup[start]
end = self.__coordinate_lookup[end]
dX = start[0] - end[0]
dY = -(start[1] - end[1])
print m.degrees(m.atan(dX/dY)) + 360
pygame.draw.line(screen,colour,start,end,2)
Run Code Online (Sandbox Code Playgroud)
我试过尝试使用角度和线条的梯度,Y 坐标向下而不是向上增加的事实让我失望,我真的很感激朝正确的方向轻推。
如何在 Three.js 中弧形或弯曲圆柱体类型的几何体(有变形)?
我想指定这些参数:
我将用滑块控制它们。我的圆柱体形状是通过用户绘制的贝塞尔曲线的挤压创建的( Three.js 中几何类的扩展)。
我还希望能够将多个弯曲效果叠加在一起。因此,弯曲可能会影响第一个零件,然后第二个弯曲可能会使圆柱体向后弯曲。
我不是最擅长数学,所以这就是为什么我要求可以在 Three.js 中完成此操作的提示或公式。我想也许我可以在中心轴上放一条线,然后用贝塞尔曲线弯曲它。从那里我可以使用线位置来影响圆柱体的顶点。这听起来是个好主意吗?
geometry ×2
3d ×1
algebra ×1
android ×1
javascript ×1
math ×1
matrix ×1
opengl ×1
opengl-es ×1
pygame ×1
python ×1
python-2.7 ×1
three.js ×1
trigonometry ×1