如何计算正常值?
好吧,假设我有一个由物体 A 的 x、y、宽度和高度制成的矩形(这都是 2d)。怎么计算才算正常呢?
Okay, so say I got a rectangle (This is all 2d) made from Thing A's x,y,width and height. How would I calculate it's normal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
青色,
您不是在寻找由叉积或 3 维定义的法线。一分钟,我会解释..
编辑:
来自
要进行数学评估,
您必须首先对欧几里得向量有深入的了解。
给定向量 A(入射角):
给定向量 B(代表被弹回的墙壁的向量):
该向量的法线(垂直)只需旋转 90 度。从数学上来说:
因此 R =
让我们首先评估点积
然后:
因此,您需要做的就是确定一个代表您要反弹的墙壁的向量(即 B)和您的入射向量(即 A)。
编辑(因为评论):
您确实应该花时间查看我发布到欧几里得向量的链接...
基本思想是定义任意数学原点。 (例如,你的墙的底部)。代表你的墙的向量只是一个从上到下(或从下到上)的箭头。由于原点位于底部,该箭头将指向 x 方向 0 个单位,但指向 y 方向 100 个单位。因此,墙壁 (B) 的矢量就是:(
请注意,墙壁的宽度并不重要 - 它与 1 像素厚、50 像素厚或 100 像素厚的墙壁的反射效果相同)。
但您需要对该向量进行归一化,使其具有单位大小(长度为 1)。因此向量变为:
这可从:
N 则为:
Cyan,
You are NOT looking for the normal as defined by the cross product or 3 dimensions. One minute and I will explain..
EDIT:
From this answer, it is obvious that what you are looking for is simply a vector perpendicular to a line. Not a vector perpendicular to a plane.
To mathematically evaluate
You must first have a firm understanding of a Euclidean Vector.
Given a vector A (your angle of incidence):
Given the vector B (which represents a vector of the wall being bounced off of):
The normal (perpendicular) to this vector is simply rotated 90 degrees. Mathematically:
Therefore R =
Lets first evaluate the Dot Product
Then:
So all you need to do is determine a vector representing the wall you are bouncing off of (which is B), and your incident Vector (which is A).
EDIT (because of comment):
You really ought to spend time reviewing the link I posted to Euclidean vectors...
The basic idea is that you define an arbitrary mathematical origin. (Say for example, and the bottom of your wall). A vector representing your wall is then just an arrow, from the top to the bottom (or the bottom to the top). With the origin described at the base, this arrow will point 0 units in the x direction, but 100 units in the y direction. Therefore your vector for the wall (B) is just:
(Note that the width of your wall is unimportant - it would bounce the same with a wall 1px thick, 50 px thick, or 100px thick).
But you'll want to normalize this vector so it has unit magnitude (length of 1). So the vector becomes:
This follows from:
N is then:
如果“法线”指的是垂直向量,请查看叉积:向量
和
叉积是
......但是纯二维中的“正常”没有多大意义。
If by "normal" you mean a perpendicular vector, take a look at the cross product: for the vectors
and
the cross product is
... but "normal" in pure 2D doesn't make much sense.
去谷歌搜索“叉积”。 (http://en.wikipedia.org/wiki/Cross_product)
获取定义矩形的边缘作为您试图穿过的向量。
Go google 'Cross Product'. (http://en.wikipedia.org/wiki/Cross_product)
Take the vectors that define the edges of your rectangle as the vectors you are trying to cross.
当心。矩形有两个可能的法线:
在平面中它有 4 个法线:
Be careful. A rectangle has two possible normals:
In the plane it has 4 normals:
如果矩形位于 XY 平面上,则法线为 (0,0,1)。不需要代数!
Well if your rectangle is on the XY plane, then a normal is (0,0,1). No need for algebra!
整个矩形的法线将垂直于矩形的平面(沿第三维)。
如果您的意思是垂直于矩形的边(但与矩形位于同一平面),那么您可以计算边的斜率,并且法线的斜率将是法线一侧的斜率。 (如果边的斜率为零,则未定义。)如果您想将此法线放在矩形上,边的中点是一个不错的位置。
The normal to the whole rectangle will be perpendicular to the plane of the rectangle (along the third dimension).
If you mean normal to a side of the rectangle (but in the same plane as the rectangle), then you can calculate the slopes of the sides, and the slope of the normal will be negative reciprocal of the slope of the side to which it is normal. (Or undefined if the slope of the side is zero.) If you want to put this normal on the rectangle, the midpoint of the side is a good place for it.
cyyprime 正在寻找的是 2D 空间中 1 条线的法线。
该法线必须满足以下条件:
m_line * m_normal = -1
,而 m_line 是线的大小,m_normal 是法线的大小。
=> m_normal = -1 / m_line
如果 m_line = 0,显然会产生错误。因此您需要特殊对待这种情况。
如果 m_line 不为 0,您将得到 2D 向量
normal_vector = (1, m_normal)
What cyanprime is looking for is a normal of 1 line in 2D space.
That normal has to fulfill the following condition:
m_line * m_normal = -1
whereas m_line is the magnitude of the line and m_normal is the magnitude of the normal.
=> m_normal = -1 / m_line
Obviously produces errors if m_line = 0. So you will want to treat that case specially.
If m_line is not 0, you get your 2D-Vector
normal_vector = (1, m_normal)
2D 中的法线是在对象中形成 90 度的向量,与应该撞击它的对象的方向相反。
这些法线有固定值,它们是:
West (1, 0);
东 (-1, 0);
北 (0, -1);
南 (0, 1);
A normal in 2D is the vector that did 90 degrees in the object, in the opposite direction of the object that should hit it comes.
There's fixed values for those normals, and those are:
West (1, 0);
East (-1, 0);
North (0, -1);
South (0, 1);