[Gambas-user] more trigonometry fun (not)

Bruce Bruen bbruen at ...2308...
Tue May 24 06:57:55 CEST 2011


On 24/05/11 14:08, Kevin Fishburne wrote:
> On 05/24/2011 12:16 AM, Bruce Bruen wrote:
>    
>> On 24/05/11 13: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.
>>>
>>>
>>>        
>> 1) Need to include i being the time increment in the same units as velocity
>> 2) Basic physics says point will move d units in i time increments according
>> to distance=velocity * time . So point will have a deltaXY of v*i.
>> Basic trig converts this to deltaX and deltaY using the old "Sign On
>> Here 'Coz Alf Has Tan OverAlls"
>> deltaX = deltaXY * sin(a)
>> deltaY=deltaXY *cos(a)
>>
>> Bobs, yer uncle, return deltaX and deltaY!
>>      
> Very true. I didn't want to include time because I didn't want to
> complicate the issue. Time is basically whatever number I multiply the
> velocity by in the mystical and unknown equation. In my case time is a
> single rendering frame, so it's not currently tied to any real sense of
> the word "time".
>
> While I appreciate the hint, what's the equation for DeltaX/Y using
> Sin/Cos/Tan if that is what's being used? I think you may be a bit more
> under the weather than I. :) And it's not even Friday... Fortunately
> when I cross the threshold I stop programming and write music for the
> game. A much more forgiving medium for sure.
>
>    
Not sure I understand "what's the equation for DeltaX/Y"?
Did you mean deltaXY?  If so it's just v*i as stated.

By the way, a few hints if I can remember my work on sonar beamplot ray 
tracing from over 35 years ago:
1) The trig is always easier if you orient your framework so the 
particle is moving (from the point of view of the trig math function) in 
quadrant 0 i.e. in the "north east" quarter of the compass.  This done 
by reflecting the angle into q0, then do the math and then de-reflect it 
back.
2) As Mr Newton said, a body will continue to move at a given rate until 
acted on by an outside force.  It may be useful for the future if you do 
the trig calcs ONLY when the particle is so affected.
3) More Newton.  If you are going to include "gravity" in your system, 
consider it to be an outside force that always acts, i.e. every clock 
tick.  In fact you may have to consider using sub ticks when particles 
are (thusly) moving along curved paths.
4) Above all make sure you use the same dimensions everywhere in your 
calc functions, do not have velocities that are points/second in some 
places and millipoints/minute somewhere else in other calcs.  This will 
preserve you sanity next week or later when you come to modify something.
5) Finally,  if you are considering 3 dimensions and therefore spherical 
trig - please don't call me!  :-) It nearly sent me mad 35 years ago, or 
maybe it did?






More information about the User mailing list