From: rusin@washington.math.niu.edu (Dave Rusin) Newsgroups: sci.physics,sci.math,comp.graphics,comp.graphics.algorithms Subject: Re: Probably an easy Circular motion question - hints? Date: 17 Feb 1995 15:14:16 GMT In article <3huogg$fgb@vixen.cso.uiuc.edu>, Sulis wrote: >I've been trying to create a simple and versatile system for allowing >points in a two-dimensional system to move in the path of a circle. >The basic way I was hoping to do it was to just give each of the points >a value K (curvature). In this way, I could leave K constant to create the >path of a circle, or vary K to give various sweeping arc paths. >... > each point has: x position, y position, dx (change in x pos), >dy (change in y pos), and K (curvature). > >So I just loop over and over: > tempdx=dx (these just so the data doesn't change in the middle of the > tempdy=dy dx and dy calculations) > > dx = tempdx + K (tempdy) > dy = tempdy + K (tempdx) > x=x+dx > y=y+dy A couple of respondents have suggested trig functions, which is a fine suggestion, but not at all necessary. Given any motion through a sequence of points p_n = (x_n, y_n), we can recreate that motion by adding to the starting point the displacement vectors v_n=p_{n+1}-p_n. Each of these in turn may be expressed in terms of the previous one in a method not unlike that suggested by the poster. Indeed, let R be the 90-degree counterclockwise rotation R(x,y)=(-y,x). Then for any non-zero vector v, {v, R(v)} is a basis for the plane. In particular, we can always write v_{n+1}=J_n v_n + K_n R(v_n). Except for a sign error, this is what the poster did, with J_n=1 and (eventually) K_n constant. Loosely speaking, v_n ought to represent velocity, and then v_{n+1}-v_n acceleration. The poster evidently intended to keep acceleration orthogonal to velocity; this is equivalent to travel at constant speed. Then, the additional statement that K be constant would make for constant-magnitude acceleration as well, which would give circular motion. Unfortunately, some accuracy is lost in the discretization, but we can preserve some features. Our choice of basis makes it clear that the magnitude of v_{n+1} will be sqrt(J_n^2 + K_n^2) times the magnitude of v_n. Thus we will have uniform "speed" (distance between successive points p_n) if we arrange it so that J_n^2+K_n^2=1. Now choosing K constant essentially implies J is too; such choices will indeed produce (discrete) circular motion. The poster's error (aside from loss of a sign) was just to have the magnitude of the speed increasing (assuming K <> 0). Of course, motion with constant speed need not require a fixed (J,K); indeed, any curve can be traversed with unit speed. One can write all such choices (J,K) in the form (J_n, K_n) = (cos(u_n), sin(v_n)), but even here, no trig is necessary; one could also write (J_n, K_n) = ((1-u_n^2)/(1+u_n^2), (2u_n)/(1+u_n^2)) for some real u_n. In either case, u_n would be related to the change in direction of the vectors v_{n+1} and v_n (of equal length). Non-uniform speed is also possible in this setting, but I'm not quite sure of the details. Suppose you wish to picture an object moving, subject to certain forces. You know then the acceleration it faces, perhaps as a function of time, position, and velocity. I'm not entirely sure how you ought to choose the J_n and K_n. When acceleration is small and slowly changing, I'm sure you'll get adequate results by taking J_n = 1+ a_n and K_n = b_n where (a_n) and (b_n) are the tangential and normal components of acceleration, respectively. But the discretization will produce unfortunate side-effects if you do this when acceleration is large. For example, if you model a planetary orbit this way, things will be fine unless you try modeling a comet passing very close to the sun. dave