Plotting Equations that Bifurcate

Alex Tweedly alex at tweedly.net
Fri Oct 30 19:12:38 EDT 2020


On 30/10/2020 22:40, Roger Guay via use-livecode wrote:
> Let’s try this again after spellchecking:
>
>
> Yes, yours is a good example of a bifurcated line. But now imagine producing this line programmatically with an equation that:
>
> Produces a constant y value of 149 as x progresses from 35 to 235 (no problem)
> Then produces 2 different but simultaneous values of y as x progresses from 235 to 335. This is the problem as you don’t want the end point of the separated lines to connect. If you place an empty line in the points after each iteration beyond x = 235 then you end up with the bifurcated lines being points rather than a solid line.
>
> How do plotting programs handle this situation????


Here are two different ways you could do it.

1. simple - assume there would (could) be two Y values for any x, and 
just calculate two series, and combine them for output.

2. harder - for each x value, keep track of the previous y value for 
each series, and if necessary, put in a 'skip' plus new value plus skip ...

NB makes for a more complex polygon; each new x value after bifurcation 
results in 5 lines added to the points.

on mouseup
    local tSeries1, tSeries2, thepoints
    if the shiftkey is down then

       -- the easy way - just allow for the possibility of two series of 
points all along
       repeat with i = 35 to 335
          -- calculate series 1
          if i < 235 then
             put i,249 &CR after tSeries1
          else
             put i, 249+(i-235) &CR after tSeries1
          end if
          -- calculate series 2
          if i < 235 then
             -- do nothing - it's the same as series 1
          else
             put i, 249+2*(i-235) &CR after tSeries2
          end if
       end repeat

       put tSeries1 &CR & tSeries2 into thePoints
       set the points of grc "X" to thePoints
       set the foregroundColor of grc "X" to "blue"
    else
       -- the harder way - multiple series ...
       -- does each step for each series ... much more complex polygon, 
but ...
       local t1, t2, tLast1, tLast2
       repeat with i = 35 to 335
          -- calculate values
          if i < 235 then
             put 249 into t1
             put 249 into t2
          else
             put 249+(i-235) into t1
             put 249+2*(i-235) into t2
          end if
          -- put in series 1
          if tLast1 is not empty then
             put i-1, tLast1 &CR & i, t1 &CR after thePoints
          end if
          -- possibly put in series 2
          if tLast1 <> tLast2 OR t1 <> t2 then
             put CR after thePoints -- blank skip over to series 2 value
             put i-1, tLast2 &CR & i, t2 &CR after thePoints
             put CR after thePoints -- blank skip back to series 1
          end if
          put t1 into tLast1
          put t2 into tLast2
       end repeat
       set the points of grc "X" to thePoints
       set the foregroundColor of grc "X" to "red"
    end if

end mouseup





More information about the use-livecode mailing list