

you can do v × p and consider x and y coordinates only. so yes, (-dy,dx) is (-6,39) and (dy, -dx) is (6, -39). V r e f l e c t e d V i n c i d e n t 2 n ( V i n c i d e n t n ) Share. So I want to figure out at any given point a vector that's popping straight out in that direction. your x2 is 45 and your x1 is 6, so your x2-x1 is 39. This is the normal vector, that is the vector that is perpendicular to the surface or the incoming Collider2D at the contact point. Obviously you can figure out a normal vector you can just divide it by its magnitude and you will get the unit normal vector. My normal is now which definitely does nto seem right to me. From the Math StackExchange How do I calculate the normal vector of a line segment: if we define dxx2-x1 and dyy2-y1, then the normals are (-dy, dx) and (dy, -dx). Another way to think of it is to calculate the unit vector for a given direction and then apply a 90 degree counterclockwise rotation to get the normal. Now if I move the line so that the intersection point = 490, 458 When I try to get the normal at this position I get

However I seem to be getting nearly the same normal regardless of it's intersection point.Ī Line at: P0 = 459, 434 and P1 = 449, 454 therefore a slope of dx = -10 and dy = 20Īn Ellipse at: Center = 449, 472 with a Major radius = 32 and a Minor Radius = 16 That definitely seems more correct programaticallly. A unit normal vector to a two-dimensional curve is a vector with magnitude 1 1 11 that is perpendicular to the curve at some point.

Vector2 normal = new Vector2( -tangent.Y, tangent.X ) You only negate one of the components when finding a 2d vector perpendicular to another. If the slope m = -(b^2 * x)/(a^2 * y) thenįloat dx = Major * Major * intersection.Y įloat dy = -Minor * Minor * intersection.X įrom thes you can construct the tangent vector:Īlso, the normal isn't the negative reciprocal.
#Get normal vector 2d code#
It looks like you're translating your slope equation into code wrong.
