[Gambas-user] more trigonometry fun (not)
Kevin Fishburne
kevinfishburne at ...1887...
Tue May 24 06:45:44 CEST 2011
On 05/24/2011 12:34 AM, wally wrote:
> On Tuesday, May 24, 2011 05:44:14 Kevin Fishburne wrote:
>> I was already helped graciously in figuring out how to translate a point
>> in a plane along its local axes at a given orientation, but now need a
>> bit of the inverse of the equation.
>>
>> I need to know the (x, y) offset of a point at a given orientation and
>> velocity. For example if a point is moving at an angle of 45 degrees (or
>> radians, take your pick), what would its x and y coordinate be
>> increased/decreased by? The variables I can think of would be:
>>
>> x1 (point's current x coordinate)
>> y1 (point's current y coordinate)
>> a (point's angle/orientation in degrees/radians)
>> v (point's velocity)
>> x2 (x coordinate offset of point's new position)
>> y2 (y coordinate offset of point's new position)
>>
>> The calculation would take x1, y1 a and v as inputs and produce x2 and
>> y2 as offsets (x1 + x2, y1 + y2 = point's new position).
>>
>> There really should be a list of basic things like this for graphics
>> programmers. I've searched for years and found practically nothing.
>> Weird, considering this has probably been done thousands of times since
>> the days of DOS. :/
>>
>> In case anyone's wondering why I need this, the equation will allow
>> particles and projectiles to follow logical paths. Currently they're
>> bound to local coordinates and ignore player orientation. Digging,
>> shooting arrows, throwing objects, etc. can't work without it.
>
> Hello Kevin,
>
> the problem seems pretty easy to solve, so I'm not sue i understand
> the question correctly.
> A good idea would be to use polar coordinates for this:
>
> P( r, a) where r = radial distance to (0,0) offset and a the angle a .
> r = sqrt( x^2 + y^2)
>
> r(p2) = r(p1) + vt ,
> new radius point 2 = 1st radius + distance to move (velocity * time)
> a does not change
>
> in cartesian coordinates:
> x2 = x1 + cos(a) * v * t
> y2 = y1 + sin(a) * v * t
>
> if you need more complex paths, using matrices is a good way.
>
> but always time is needed to calculate. You did not mention time t
> so i assume i did not understand the question.
Hi Wally. I'm going to test that code, but my gut tells me that it's
correct. The two Cartesian coordinate lines are surely correct (I will
confirm in the next couple of days).
The reason it seems easy and that you think you may have misunderstood
my question is probably because I'm really bad at math other than basic
algebra. It's a hell of a thing, as I'm dangerously clever in many other
ways. Thank you, and as I said I'll let everyone know if that does the
trick. I'll even put up a YouTube video of the righteous usage of the
algorithm to show how cool its implementation is. :)
--
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271
More information about the User
mailing list