[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> 3D Orange peel with "glitched" removed



I did not determine the exact cause because I do not understand Tom's
code in detail. But if color appears wrong it's likely one of 2 things.
The polygon is either not planar or not convex. To fix the problem
I Split the quadrilateral into 2 triangles, this guarantees all polygons
are planar and convex. I don't know if the cause was due to an algorithm
problem or accumulation of numerical errors which becomes pretty
significant in this exercise. By using triangles it basically avoided
both problems.

Using triangles in 3D graphics is very common because of these properties
and it's always pretty easy to breakup any polygon into triangles.

to aaa
  cs
  setsc [0 0 0]
  perspective
  setlight [0 0.2] ask -3 [pu setposxyz [100 100 100]]
  rt 150 ; Change this to change orientation of peel

  setpc [255 160 40]
  orangepeel 200 15
  ; Uncomment the rt 180 in the next line to turn it into a ball.
  setpc 4 ;rt 180
  orangepeel 200 15
  wait 100
  polyview
  repeat 72 [ask -1 [fd 200 down 5]]
end

to moveto :pxyz
  setorientation towardsxyz :pxyz
  fd distancexyz :pxyz
end

to orangepeel :radius :strips
; Tracks a spiralling path down around a sphere.

  localmake "v 0
  localmake "r 0
  localmake "hanglestep 7.5
  localmake "vanglestep :hanglestep/:strips
  localmake "stripheight 360*:vanglestep/:hanglestep
  localmake "oldlowerpos 0
  localmake "oldnextpos 0

  setturtle 0
    localmake "startpos posxyz
    pu fd 10
    localmake "startposmoved posxyz
    bk 10

  setturtle 1
    pu
    setposxyz :startpos
    setorientation towardsxyz :startposmoved

  until [and not (:v < 180) not (:r < 350)] [
    setturtle 1
      pu
      rt :r
      ifelse :v < 180 [up (:v - 90)][up 90]
      fd :radius
      localmake "nextpos posxyz

      if (:v < 180 + :stripheight/2) [
        bk :radius
        ifelse :v > :stripheight/2
          [ifelse :v < 180 [down :stripheight/2][down :stripheight/2-:v+180]]
          [down :v]
        fd :radius
        localmake "lowerpos posxyz
        ask 2 ~
          [
          ; if :oldnextpos has been set then build polygons
          if listp :oldnextpos
            [
            ; Split the quadrilateral into 2 triangles
            ; This guarantees all polygons are planar and convex
            pu
            setposxyz :lowerpos
            pd

            polystart
            setposxyz :nextpos
            setposxyz :oldnextpos
            setposxyz :lowerpos
            polyend

            polystart
            setposxyz :oldnextpos
            setposxyz :oldlowerpos
            setposxyz :lowerpos
            polyend
            ]

          make "oldnextpos :nextpos
          make "oldlowerpos :lowerpos
          ]
        bk :radius
        ifelse :v > :stripheight/2
          [ifelse :v < 180 [up :stripheight/2][up :stripheight/2-:v+180]]
          [up :v]
        fd :radius
      ]

      bk :radius
      ifelse :v < 180 [down (:v - 90)][down 90]
      lt :r

    setturtle 0
      pu ; ifelse posxyz = [0 0 0][pu][pd] ; Draw main track
      setposxyz :nextpos

    localmake "r :r + :hanglestep
    if :r > 360 [localmake "r :r - 360]
    localmake "v :v + :vanglestep
  ]

  ; Reset turtle 0 to original state (though it may have rolled a bit...)
  setturtle 0
    pu
    setposxyz :startpos
    setorientation towardsxyz :startposmoved
end

--
===============================================================
George Mills (mills@softronix.com)
http://www.softronix.com/
The www page contains some very powerful educational software.
Our single most important investment is our kids.
---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home