Bring 3 Vector 3s together
I'm dealing with a scenario where I have 3 Vector3 stored in variables. I need to be able to "contract" those 3 points together, as well as expand them.
Please see example image below. This is happening in a 3D space and the 3 points can be at any position and the whole triangle might be rotated too (although all 3 points would have the same rotation).
I am able to get the scale to shrink by multiplying the points by a decimal. However this has the negative effect of leaving the triangle completely.
Any help is appreciated!
Answer by Hellium · Jul 03, 2018 at 02:28 PM
Compute the point to use so as to shrink the triangle (can be the centroid or any other point)
Example here : https://stackoverflow.com/questions/9815699/how-to-calculate-centroidanswer-19750258 (need to be adapted to take Vector2
instead of PointF
)
Then, compute the new position from the centroid:
Vector2 centroid = GetCentroid( new List<Vector2>() { pointA, pointB, pointC } ) ;
Vector2 centroidToA = pointA - centroid ;
Vector2 centroidToB = pointB - centroid ;
Vector2 centroidToC = pointC - centroid;
pointA = centroid + centroidToA.normalized * centroidToA.magnitude * percentage;
pointB = centroid + centroidToB.normalized * centroidToB.magnitude * percentage;
pointC = centroid + centroidToC.normalized * centroidToC.magnitude * percentage;
Your answer
Follow this Question
Related Questions
how to calculate the angle between two vectors? 6 Answers
Convert 2D direction vectors to 3D vectors around sphere 2 Answers
Non physics determinism of floating point math across platforms 1 Answer
Unity plane constructor bug? 1 Answer
Get a Vector3 to always have a radius of 1 from 0, 0, 0 2 Answers