Comments and answers for "How can I get the distance between two points, but in just one relative axis?"
http://answers.unity.com/questions/1570483/how-can-i-get-the-distance-between-two-points-but-1.html
The latest comments and answers for the question "How can I get the distance between two points, but in just one relative axis?"Comment by JVene on JVene's comment
http://answers.unity.com/comments/1572889/view.html
Speaking in Euler angles, let's say the object is rotated 45 degrees clockwise. If you take the two points as given, the rotate the pair 45 degrees counterclockwise, they're "unrotated", they are thus aligned to the world axis.
----------
To be clear about the best solution to your problem, carefully consider what you know about the object itself. You're getting collision points, but do you know the object's width in the x axis? If you did, the blue line is always that length no matter what the angle of the red line.
----------
As to "depending on the leg of the triangle, the use of sine or cosine was different" - that is driven by the law of sines (when you have angles and a side or two), or the law of cosines (when you have sides, but need angles). In your case the red line is always the hypotenuse of a right triangle, such that you can always reorient the values to represent only one possible triangle orientation (that is, you're always considering the same leg, not either leg). This is because the 90 degree angle is fixed opposite the hypotenuse, so if you know either of the other two angles, then you know all 3 angles (the third has to be 180 - ( 90 + angle ) ).Sun, 18 Nov 2018 15:46:59 GMTJVeneComment by Feref2 on Feref2's comment
http://answers.unity.com/comments/1572761/view.html
Thanks for your detailed explanation. I also thought making use of trigonometry the same way you did. However, depending on the leg of the triangle, the use of sine or cosine was different. I was having trouble identifying which to use, since the points may differ from the diagram and sometimes I will get them only when the object is rotated and other things that really confused me.
But then you say there´s a simpler solution, "unrotate to world axis alignment". How can I achieve that?Sun, 18 Nov 2018 05:05:20 GMTFeref2Comment by JVene on JVene's comment
http://answers.unity.com/comments/1572745/view.html
What you're looking for is a local relative X axis (local being key to recognizing what you're looking for). Your diagram is the most informative on this point, as I'm not entirely sure there's a clear label.
----------
Note, by your diagram, the blue line will be the width of the rectangle, so if you know that you can just take it. Otherwise, your solution is trig, but could be be basic Pythagoras, in a sense. The distance of the red line is the hypotenuse. Unfortunately, you next need the base (the line of the implied triangle you haven't drawn). That is the distance of apparently the local y coordinates of the two points, from which you can algebraically swap Pythagoras around a bit to get the other leg.
----------
On the other hand, you have a right triangle. If you could calculate the angle between where the red and blue meet, you can deduce the rest (the third is 90), and with the length of the red line you can use law of sines to complete the triangle and thus know the blue line length.
----------
However, you might find it simpler to "unrotate" the object itself, or more accurately, unrotate the two points to a world axis alignment. Then the blue line would be merely a subtraction of the x coordinates.Sun, 18 Nov 2018 03:59:59 GMTJVeneComment by Feref2
http://answers.unity.com/comments/1572502/view.html
@JVene correct me if am wrong, but I think that Vector3.Distance takes the distance like the red line:
![alt text][1]
And I need the blue one, which i can´t get by substracting the x coordinates like you say, because that would give me something like this:
![alt text][2]
[1]: /storage/temp/127874-captura-de-pantalla-19.png
[2]: /storage/temp/127876-captura-de-pantalla-20.pngSat, 17 Nov 2018 07:46:08 GMTFeref2Comment by JVene
http://answers.unity.com/comments/1570730/view.html
Distance along the x axis is merely the absolute value of the difference (subtraction) of the x coordinates.Sat, 10 Nov 2018 22:48:00 GMTJVene