- Home /
Calculate new point by Normal vector
Hi all! I need to apply an offset (AK, KC) to point A, i.e. Vector2d and do it perpendicular to AB as it shown on the picture.
Answer by Bunny83 · Feb 03, 2021 at 10:53 AM
So this is a 2d problem, right? Because otherwise your distance AK would trace a circle around the normal. So K wouldn't be a point but a circle. So in case we talk about 2d it's actually quite simple. First get your normal vector AB and normalize it. So our normal points towards B. To get the perpendicular to your normal all you have to do is rotate the normal by 90° this is super simpler in 2d because a 90° rotation just means swapping the two components and inverting one of them. Which component you invert dictates the rotation direction. Since we need a counter-clockwise rotation we just do:
Vector2 n = (B - A).normalized;
Vector2 p = new Vector2(-n.y, n.x); // 90° counter clockwise rotation
With those two vectors it's just ordinary vector addition:
Vector2 C = A - n * KC + p * AK;
This should give you the point you're looking for.
Note if you need this in a 3d environment you need to specify more data as the problem is not solvable with the current information.
In your particular case the point C would be (4.2, 5.4) unless I made a mistake ^^ Did the calculations in my head
Of course you did them in your head Bunny, you blim$$anonymous$$ genius
:D actually I did. Currently I don't have Unity or a calculator at hand. I just through about it and realised that the vector AB has components 3 and -4. So the length of that vector is 5 (you know 3-4-5 right triangle so 3²+4² ==25 --> 5) So the normalized version of AB is just (3/5,-4/5)== (0.6, -0.8). The rest is just simple multiplication and addition. I do admit that I write down intermediate results here in the text field ^^.
Without the 3-4-5 shortcut this would be almost impossible because who can calculate square roots of non square number in the head? ^^
Answer by jackmw94 · Feb 03, 2021 at 10:52 AM
Since you know AK and KC then you can determine AC, which is AK + KC.
Then to find the coordinates of C, you can do A + AC = C.
Add a comment if I have misunderstood this :)
I don't understand the last calculation. How can you add a vector to a point?
AC doesn't give you the x and y position. Doesn't it just give you the magnitude?
It's very possible I'm having an absolute mare with this but:
A is a point at (2, 5)
AB is a vector offset of (3, -4)
To find coordinates of B you do A + AB
B = (2, 5) + (3, -4) = (5, 1)
I imagined AC would be the vector from point A to point C, which you can find by adding the vectors from points A to K and K to C. Therefore the coordinates of C would be A + AC like how we found B's coordinates from A + AB.
Plz let me know if I'm being an idiot :D
I think the confusion is that in math we usually write points and vectors between points with capital letters. So A, B, C and K are points while AB is the vector from A to B. I think what the OP meant to say is that |AK| and |KC| are known, not the actual vectors. At least that's what I can read out of the image since it just says "AK = 2" and "KC = 1"
As I understood the problem, his AK and KC are not known vectors but just the lengths of those vectors. $$anonymous$$aybe I got it wrong, but if the Vectors AK and KC are known, yes, then it's just the addition of those 3 vectors.
Your answer

Follow this Question
Related Questions
Trig function problem 1 Answer
simulate a circle move 2 Answers
Finding coordinates based on an angle and distance? 3 Answers