[Date Index]
[Thread Index]
[Author Index]
Re: help with trig(?) calculation
*To*: mathgroup at smc.vnet.net
*Subject*: [mg13234] Re: [mg13155] help with trig(?) calculation
*From*: Robert Pratt <rpratt at math.unc.edu>
*Date*: Fri, 17 Jul 1998 03:17:34 -0400
*Sender*: owner-wri-mathgroup at wolfram.com
Unless your screen is square (which I doubt), the example (320,240)
with 45 degrees hits the point (560,0), not (640,0). Use the angle
ArcTan[240/320]=ArcTan[3/4] if you want to hit (640,0).
The following commands seem to do what you want, if you enter alpha in
radians (convert if necessary).
WithinBoundaryQ[{x_,y_}]:=(0<=x<=640) && (0<=y<=480)
intersect[{x_,y_},alpha_]:=Module[{u,v,t,sol},
{u,v}={x-320,240-y}+t{Cos[alpha],Sin[alpha]};
sol=Select[Union[Solve[Abs[u]==320,t],Solve[Abs[v]==240,t]],
Positive[t/.#]&];
Select[Transpose[{(u/.sol)+320,240-(v/.sol)}],WithinBoundaryQ[#]&]]
intersect[{320,240},45 Pi/180]
{{560,0}}
intersect[{320,240},ArcTan[240/320]]
{{640,0}}
intersect[{320,0},3 Pi/2]
{{320,480}}
intersect[{0,240},0]
{{640,240}}
Rob Pratt
Department of Mathematics
The University of North Carolina at Chapel Hill CB# 3250, 331 Phillips
Hall
Chapel Hill, NC 27599-3250
rpratt at math.unc.edu
http://www.math.unc.edu/Grads/rpratt/
On Mon, 13 Jul 1998, Leon Bryant wrote:
> i need some help from the "gurus". i am a multimedia programmer working
> in San Antonio, and need help with a programming idea that involves
> some simple(?) trig.
>
> the problem:
>
> i have a display area (computer screen) that has the dimensions 640 by
> 480 units (pixels).
> my program sets the dimensions of this rectangle to:
>
> TL - 0,0
> TR - 640,0
> BL - 0,480
> BR - 640,480
>
> what i would like to do is give the coordinates of a point on the
> screen, an angle (or a second point), and devise an algorithm that will
> plot where the imaginary line would inintersect the boundaries of the
> display area.
> for instance:
>
> point: (320,240) (centered on screen) angle: 45 degrees
> intersection point: (640,0)
>
> this one's intuitive since the starting point is centered on the screen,
> and the angle is 25% of 360 degrees, but i'm stumped with anything more
> irregular.
>
> can you explain how i'd do this? can it be put into a simple formual?
>
> email: leon.bryant at usaa.com
Prev by Date:
**Re: Can it be done - easily?**
Next by Date:
**Re: Limit doesn't work properly**
Previous by thread:
**help with trig(?) calculation**
Next by thread:
**Problems with numerical precision**
| |