# Can I get (Ax, Ay) from a known dot product?

Hello!

I am wondering if there is a way that I can move vector by a given dot product value.

For example, if I want a vector to be at the point when its dot product is 0.7, I want to know the new coordinate points.

I hope that makes sense

Thank you!

I perceive your question as incomplete, but my guess is: for a given vector a give me the vector b such that a*b = 0.7

If thatâ€™s correct, there is a very simple solution which is: b = 0.7 * a / a.magnitude. But this is just the trivial one of an infinite amount of possible solutions.

but to avoid any further guessing, could you add some more information? What do you actually want to use this for?

just for completeness sake the definition of the dot product (stolen from Dot product - Wikipedia)

1 Like

Yes, I believe you have interpreted my question perfectly!

I am wanting to apply Hookâ€™s Law to the dot product. Thusly giving a spring like effect to a system of nodes, visually connected by lines draw on the GPU. I know the original A and B vectors, and therefore I do have the magnitudes available to me.

I believe the magnitude is what will help me solve for the 2nd unknown in the case the two unknowns, bx & by.

Thank you @tjmaul !

1 Like

If I interpret your post correctly you have a network of nodes connected through springs. For that, there is no need for the dot product.

assuming you have two nodes A and B with their respective position vectors a and b, you can get the connecting vector like this

x = a - b

If for each spring you have the rest length L and the stiffness coefficient c, the force exerted on the two connected nodes is given by

f = (x.magnitude - L) * c * x.normalized

Explanation: itâ€™s the actual distance between the nodes (magnitude) minus the rest length L (length of the spring without any forces) times the stiffness.

For the other node itâ€™s obviously -f (negative f)

edit: Added the x.normalized to the assignment of f. Without, youâ€™ll only get the scalar force but youâ€™ll need the vectorial version

I think this makes sense, I will try to apply it.
I should post a picture, this

@tjmaul They are supposed to be behave more grass like. Right now, they behave moreâ€¦ web like. Each yellow dot is a node, the red is just a line drawn between each node.

The part that I believe I am struggling with is applying Force, as an iterative time step. Iâ€™ll keep trying!

Ah I see. Thatâ€™s why you wanted to incorporate the angle :). I think a better mental modal would be a torsion spring. So each node is a torsion spring and the link is infinitely stiff.

Is this a 2D problem? Is the grass just a visual feature? Is there a reason not to use the provided joints?

Yes! I think that is exactly what I am after. I would especially love for cascading effects, like a force on the top-most node will translate some of the force down to the othersâ€¦ I believe that is what I want, to have the whole grass bend, instead of just the top piece.

It is indeed a 2D problem, and just a visual feature. I am writing it in hlsl/compute shader, I pass in a circle colliderâ€™s positional data before each update and do the collisions myself in the shader. I am thrilled with how I figured out to do the circle collisions, but my physics calculations are funky. All Iâ€™m doing is multiplying the distance of each node from its original position, by some constant, minus a dampening, times deltaTime. So that aspect is very crude
I can absolutely use the joints, any data at all really, itâ€™s all under my control

I see. Can you tell a bit more how you draw the blades of grass after calculating the position?

My way to approach this would actually be just one mass node simulating the tip of the blade of grass and then draw a spline for each grass blade, starting from a static point down from the initial position of the tip and a tangent that goes straight up.

You then only have to store each nodes initial position (to which it is always drawn to), its current position and velocity. With that you can easily implement a spring system (like Iâ€™ve elaborated above, with rest length 0) and add a damping term ( add a force of -d * velocity, counteracting the current velocity).

To disturb the grass, you can basically do the same as youâ€™re doing right now.

does that make any sense?

I am using Bresenhamâ€™s algorithm to draw each pixel of a line between each node.

I really like your suggestion, it would be a lot more simple. One reason I went with multiple nodes for each grass blade, is so that I can have little animals munch the grass down. Bresenham does have an algorithm for splines though, too.

I think I am already doing the physics as you mentioned. I am storing each nodeâ€™s initial position, and as its dynamic position changes, a velocity, springiness, dampening, and deltaTime variables are applied to it.

The issue that comes in with that is the fact that I have multiple nodes, and that each node is not currently influencing the other. so it looksâ€¦ almost spider webby, as each node tries to oscillate back to its original position, instead of its original vector. I thought that maybe a reverse dot product (solving for Vector B), would be a start to correcting that. Perhaps I need a rethink on how exactly I should design this. This is all very challenging to think about, but itâ€™s fun to solve it