makertaya.blogg.se

Find perpindicular vector 2d
Find perpindicular vector 2d





The numerator is the following then: (it seems you are calculating the numerator an unknown way, I don't understand why you did it because this is the proper way to calculate the numerator for the linked formula, perhaps this is why you got totally wrong distances.) float _numerator = abs((b * xB) - (a * yB) - (b * x1) + (a * y1)) we have another point somewhere else: B(xB, yB)įor the testing here are two rows of random values:.we have a point on the line (the centre of the sprite): P(x1, y1).Let us implement the formula again, according to the contents of your original link. the distance has to be positive, so I do the following Here is the code: // first I am working out the c Value in the formula in the link given aboveĬGPoint pointFromVector = CGPointMake(bh.incomingVector.x*,bh.incomingVector.y*) įloat result = pointFromVector.x + pointFromVector.y įloat test = (bh.incomingVector.x * bh.position.x + bh.incomingVector.y * bh.position.y + result2)/sqrt(pow(bh.incomingVector.x, 2)+pow(bh.incomingVector.y, 2)) IncomingVector = (-0.7,-0.3) //this is the vector the sprite is moving alongīh.position is the point I want to calculate the distance to So what do I do wrong ? Have a look at the image I provided.

find perpindicular vector 2d find perpindicular vector 2d find perpindicular vector 2d

However I tried it, and if I log it, it returns an unbelievably high value that is 100% false. Now, quite some time ago I learned to calculate the perpendicular distance from a vector to a point (first formula on this page ). I have another point whose coordinates I have - let's call them (xB|yB). I have a sprite that moves along a vector (-0.7,-0.3).







Find perpindicular vector 2d