ANN: Rolling graphics

Jim Hurley jhurley at infostations.com
Thu May 12 10:43:41 EDT 2005


To see this stack, run this from the message box:

go url "http://home.infostations.net/jhurley/Rolling.rev"

(DO NOT CLICK ON THE LINK.)

Warning: This is of importance only to those interested in 
programmable graphics.

As an offshoot of something else I was working on, I needed a way to 
set a disk rolling down a curve without slipping. I ran into some 
interesting problems.

The curve I chose was a bezier line because I needed to be able to 
change the shape easily. But when I used the points of the bezier 
graphic, the motion of the rolling disk was herky-jerky, as some 
points exhibiting retrograde motion, i.e. fall *up* hill-see the 
first card on the stack.

The origin of the problem turned out to be round-off errors in 
setting the points of the bezier graphic line. Run Rev will only 
accept whole numbers for graphic points. It will accept fractional 
points for the loc of objects, e.g.100.88, 200.33, but not for 
graphic points. (If you would like to see this changed, vote for 
bugzilla 356) So it is necessary to round off the calculated line 
coordinates to whole numbers. (Run Rev doesn't round location sites; 
it truncates them.)

To illustrate the difficulty this causes, imagine you need the slope 
of the line at some point. (I need this slope so that I can position 
the disk so that the slope of the disk and the curve are the same at 
the point of contact.)  To get the slope you compare two adjacent 
points on the curve; say the calculated points are:

9.500001, 10
  and
11.4999,11

If you round these points for the graphic point, then dx = 11 - 10 = 
1, and dy = 1, so that the slope, dy/dx is 1.


If you use the calculated  values, dx = 2 (approx.) and dy = 1, so 
that the slope is .0.5

Big difference. 100% error. (This problem *increases* as the number 
of line points increases.)

So I went back to the program defining the bezier curve and, beside 
the rounded points for the graphic display of the curve, I also 
created a set of "customPoints" for the curve; these are the actual 
calculated points derived from the bezier formula. Notice the 
substantial difference in performance-card one.

There is talk of Run Rev including bezier curves in a future release. 
This will be great, but for some applications you might need the 
precise, calculated points and not just the rounded graphic points.

It might be nice if Run Rev were to include these calculated 
coordinates as the graphic points-but displayed, of course, only the 
rounded values-but this would entail a bit of overhead. If these 
calculated points were included, the command: put the points of 
graphic "myBezier" would list the full precision with which Run Rev 
performs calculations. (What is this, by the way? I couldn't find it 
in the docs.)

  And there is a fix; namely: calculate the points and put them in a 
custom property of the curve. To do this you will need the positions 
of the bezier handles. Complicated if there are multiple bezier 
controls.

More than you wanted to know.

Jim




More information about the use-livecode mailing list