Re: C Programming: A Modern Approach - Chapter 15 Exercise 5



richard@xxxxxxxxxxxxxxx (Richard Tobin) writes:

> In article <pan.2005.07.22.09.48.30.184627@xxxxxxxxxxx>,
> Simon Morgan <me@xxxxxxxxxxx> wrote:
>
> >The task is to modify it so that it alternates between distribution of the
> >extra spaces favouring the end of the line and the beginning of the line.
>
> It's not really answering your question, but this is an example of the
> large class of problems that can be solved with something equivalent
> to Bressenham's algorithm. That algorithm is traditionally used for
> drawing straight lines on a pixel display, but can be used for all
> kinds of problems where you want to approximate division using integer
> increments.
>
> In this case, suppose you want to divide 8 spaces among 5 gaps. Start
> with zero. At each gap, then add 8 and subtract off as many 5s as you
> can, and for each one add a space to that gap. Then proceed to the
> next gap using the remainder as the starting value.
>
> So we have
>
> 0+8 = 8 = 1*5 + 3 => 1 space
> 3+8 = 11 = 2*5 + 1 => 2 spaces
> 1+8 = 9 = 1*5 + 4 => 1 space
> 4+8 = 12 = 2*5 + 2 => 2 spaces
> 2+8 = 10 = 2*5 => 2 spaces

Right, except Bresenham's algorithm usually adds 2x number of spaces
at each gap, and subtracts 2x number of gaps for each "increment"
(which is printing a space in this case), so that the comparison value
of 1x gaps can be used, which is "1/2" in the rationalized number
system.
.



Relevant Pages

  • Re: [PATCH] TX algorithms, missetting IFF_OACTIVE and if_timer
    ... less driver code when converting to use the precomputed pointers, ... but this gap is part of the existing algorithm. ... FreeBSD committer ...
    (freebsd-net)
  • Yet Another Factoring Algorithm (yafa)
    ... I would like to have comments on the following algorithm. ... mathematica/maple lingo. ... ranges through the set of prime numbers (until a certain ... Here is the code (in GAP): ...
    (sci.math)
  • Re: C Programming: A Modern Approach - Chapter 15 Exercise 5
    ... >The task is to modify it so that it alternates between distribution of the ... >extra spaces favouring the end of the line and the beginning of the line. ... to Bressenham's algorithm. ... At each gap, then add 8 and subtract off as many 5s as you ...
    (comp.lang.c)
  • Re: Quiver spacing for small sails
    ... By these operations I only wanted to show that when you add and subtract ... What does Steven mean by 20% gap? ... Scaling down by 20% ... Bart ...
    (rec.windsurfing)