Gray line (fixedVerticalTube) is a fixed vertical line on right.
Blue line (extendingParentTube) is slanted and extending (by changing second point’s Y).
Green line (slantingChildTube) has one point on top of gray line and passes thru the top of Blue line.
When blue line extends (by translating its second point on Y axis), green line should also move up/down keeping it’s one end connected with the gray line. This effectively rotates the green line on Z axis.
Playground link (https://www.babylonjs-playground.com/#165IV6#2893) has transformnode created at the end of blue line. I want to rotate Green line such that its one end point stays on gray line and it passes thru the transformnode (purple sphere). Is there any way to find rotation value required to achieve this?
(Green line can be a mesh object so drawing Green line passing thru top of Gray line and CoT isn’t an option.)
In this playground link: https://www.babylonjs-playground.com/#165IV6#2893. I have the Blue line extending on Y axis.
I want to move Green line along with the Blue line while keeping its one end connected to the top of Gray line.
In my application, I know the Y translation of Blue but not aware about Z rotation angle of Green line. So as Blue line extends on Y, I need to find the Z rotation of Green line such that one end of Green line stays on Gray line and another on top of Blue line.
It feels like a trigonometry question on a math test
If I understood correctly, you want the green line to always be connected in one edge to the gray line, and the blue line to airways be connected to the green line at the right point. Is that right?
As you know the length of the blue line and it’s point in space and the connection point between gray and green, you can stretch a line between those points to calculate the green line’s angle. Then rotate the green line at the right axis using the rotate function.
Thanks for the solution, Raanan. You’ve understood it correctly.
Based on the start & end of Green & Blue lines, I think I can find Green line’s angle using Pythagorean equation.
Thank you.
I’ve tried to apply simple equation but unable to find the angle of Green line from it’s attachment (on Gray line) and top of Blue line.
Any reference would be helpful.
Thanks.
@dhruv_er sorry for the delay in my answer, got caught up in other things.
Maybe with a little re-thinking it is not a trigonometry question, provided I have the correct understanding of your requirements @dhruv_er…
Taking a slightly different approach.
Let O and A be fixed points in space. Let P be any point such that the distance from O to P ≤ r for r a positive number. Extend a line from O through P to a point B such that |OB| = r. Find B.
Draw the lines OA and AB. In Babylon.js use cylinders for lines.
Thanks, JohnK. Your provided solution (O.add(P.subtract(O).normalize().scale®)) is really a great way to draw the line.
I need to place a mesh object in place of “slantingChildTube”. Mesh object looks like a line but it’s a 3D shape.
Is there any way to find an angle of a “slantingChildTube” from vector “O” to vector “B”?
I will use that angle to rotate 3D mesh and display in place of “slantingChildTube”.
Here is an attempt to find the angle : https://www.babylonjs-playground.com/#0RYA8I#1. I’m not sure it’s correct angle.
Currently you are finding the angle between the position vectors O and B at the origin. To find the angle between the grey and green tubes you need to find the angle between the vectors (A - O) and (B - O)
I’m trying to find the angle between vector “O” and center of sphere in https://www.babylonjs-playground.com/#0RYA8I#4. Using the angle, I want to rotate “slantingChildTube” (Green line) at “O” (Center of rotation).
Is it possible to find angle between “O” and center of sphere that rotates “slantingChildTube” on “O” and pass thru the center of sphere?
There are additional issues I will point out afterwards. However as I said before the angle between two points gives you the angle between the position vectors of those points. The method Angle.BetweenTwoPoints is misnamed and should really be Angle.BetweenTwoVectors.
Consider this diagram where W is the world origin for all positions (vectors)
After further investigation I found I had also made some wrong assumptions. Some by not reading the API fully since the ‘AngleBetweenTwoPoints’ method is for Vector2s not Vector3s.
What the API does not make clear is what its name implies, ie it will only work for two points given by their position vectors in Cartesian space.
In addition the calculation ‘AngleBetweenTwoPoints’ makes is wrong and I have raised a bug.
Now in the examples being used in your case Vector2s could be used. Since you are using Vector3s and you want a more general solution see https://www.babylonjs-playground.com/#0RYA8I#5