Hi,
i have two nodes
i awnt to move my node1 by distance with the respect that there is static length between the two nodes
to do that , i must have angle
to get the direction my idea is : if the node1 in right of node2 then the node2 must move in this direction (right)
if the node1 in the left of the node2 then the node2 must move to the left
to program that i think to calculate the distance between node1 and node2
If you want two nodes to be positioned relative to each other attach one of them to the other as a child for the duration of the linking. When you want to stop the node moving relative to the other one simply attach it to a differnt parent and position it at the position you want.
You can use the convertLocatlToWorldPosition and convertWorldToLocalPosition methods to calculate the positions that you need when you attach and detach the nodes. There are also methods for orientations if you want. The scene graph is very powerful this way with nodes all being positioned relative to their parent.
If you want two nodes to be positioned relative to each other attach one of them to the other as a child for the duration of the linking. When you want to stop the node moving relative to the other one simply attach it to a differnt parent and position it at the position you want.
and i will not move node1 , so when i attach node2 to node1 , when i move node1 node2 move , in my case i will move just node2 , and node1 stay in it's position
please read my first post you will understand what i want to do , and you will find my idea that i could not applicate because i am not good in math
You can also rotate node 1 to move node 2 if it is attached without moving node one. I had a look at your other post and I think I know what you are trying to figure out. I suggest you draw this out on paper as you go.
If I understand you have the following information
Position of Node 1. (p1)
Position of node 2. (p2)
Distance between node 1 and 2 (len1)
Distance you want to move node 2 (len2)
you want to find a position p3 that is
len1 from node 1
len2 from node 2
If you draw lines between all of those points you get a triangle but it is not a right angle triangle. The triangle lines are
p1 -p2 = len1
p1- p3 = len1
p2 - p3 = len2
Since there are two lines with the same length we can turn this into a right angle triangle by halving it along the p2-p3 line. call the new half way point p4
p1-p2 = len1
p2-p4 = len2/2
p1-p4 = len1^2 - (len2/2)^2
You now have a right angle triangle with enough sides to get a triangle. Don't calcualte p1-p4 you don't need it. p1-p2 hypotenuse, p2-p4 is the oposite since we want to find the angle next to p1. so we can use sine to calcualte the angle.
arcsin (len2/2)/len1 = ang1.
we started with two triangles and halved them so to get the angle you need to double ang1.
ang2 = ang1 *2
Now we have the angle we need to rotate the point by. If node2 is attached to node 1 you can turn node1 by +/- ang2 to get the new position.
Or to do it manually we need the world angle to apply the angle we just found to.
p1-p2 = dp2 position relative to p1.
world angle = arctan2(dp2.y /dp2.x)
ang3 = (world angle +/- ang2)
p3.x = len1 * cos (ang3)
ps.y = len1 * sin (ang3)
That is a step by step for doing it in 2d if you need to do it in 3d you'll have to understand that then add the steps for calcualting the z position.