- Home /
How to get vector X distance from point on Y angle?
When I modded warcraft3 there was a function called (in jscript syntax) PolarOffset(v : Vector2, distance : float, angle : float) : Vector2
It would generate a point X distance and an Y angle from the input. No matter the angle, it would always be X distance away from the given point.
I've done google searches on it, but it's a wc3-only term so my luck ends there. Does anybody know the proper term for this?
SOLUTION
function PolarOffset(origin : Vector2, distance : float, angle : float) : Vector2{ //o = angle
var x : float = origin.x + distance * Mathf.Cos(angle * Mathf.Deg2Rad);
var y : float = origin.y + distance * Mathf.Sin(angle * Mathf.Deg2Rad);
return Vector2(x,y);
}
Answer by AliAzin · Sep 25, 2010 at 02:50 PM
Take a look at this. You can simply convert between polar and cartesian coordinates.
function $$anonymous$$rOffset(origin : Vector2, distance : float, angle : float) : Vector2{ //o = angle var x : float = origin.x + distance $$anonymous$$athf.Cos(angle $$anonymous$$athf.Deg2Rad); var y : float = origin.y + distance $$anonymous$$athf.Sin(angle $$anonymous$$athf.Deg2Rad); return Vector2(x,y); } Angle : 0-360
Answer by windexglow · Sep 25, 2010 at 09:57 PM
function PolarOffset(origin : Vector2, distance : float, angle : float) : Vector2{ //o = angle
var x : float = origin.x + distance * Mathf.Cos(angle * Mathf.Deg2Rad);
var y : float = origin.y + distance * Mathf.Sin(angle * Mathf.Deg2Rad);
return Vector2(x,y);
}
Answer by SirGive · Sep 27, 2010 at 09:32 AM
I do believe that logically, you're speaking about the Distance formula.
Distance between two points = squareroot( (x2-x1)(x2-x1) + (y2-y1)(y2-y1) + (z2-z1)*(z2-z1)). If you set a variable equal to that formula, where x1 is the center and x2 is the position your limiting from. You could then rotate x2 based on x1's coordinate system. I hope I am understanding you question.
Answer by Proclyon · Nov 16, 2010 at 01:41 PM
Isn't what you mean simply the vector length of the radius of a circle? I have no idea what all this polar stuff is everyone seems to be mentioning. But if angle isn't part of the equasion, just ignore it right? Leaving behind one thing, a 2 dimensional line with a length. So why make it more complex than that, since the angle can't change the length
Your answer
Follow this Question
Related Questions
how do i keep a gameobject in between the union of 2 or more than 2 circles 0 Answers
Angle between 2 GameObjects and center of screen 2 Answers
Angle between two lines in 2D 3 Answers
Closest point on multiple lines? 2 Answers
Draw line to a specific angle 2 Answers