Sign In/My Account | View Cart  

advertisement

AddThis Social Bookmark Button

Article:
  Introduction to Cocoa Graphics, Part 2
Subject:   what is this thing called triangle?
Date:   2001-11-19 20:47:37
From:   psheldon
Response to: got a great doubt

Embarrassment made me doubt doubt.
;-)
Bezier class includes methods such as lineto and moveto that will not match tangents and this sets a precident for this other sort of thing getting into the class. I'm also recalling that it makes sense it be in the class without bugs because I recall that there was an option for rounding the corners of a border, so that Apple coders would have gotten the bugs out from that concept, though it is not precisely the same problem, plausibly a similar one. So now I must try to code not so much fearing that I will spend a long time while it doesn't work fearing that Apple might be wrong. The game's afoot!
Full Threads Oldest First

Showing messages 1 through 12 of 12.

  • changed one line of code for info
    2001-11-19 21:36:51  psheldon [View]

    We saw triangle was of class you investigated, NSBezierpath class and not Bezier class. Sorry, my memory became lazy. Must have precise memories as computers are unforgiving.
    ;-)
    Info (in subject line), as defined by AI guys is surprise (for me sometimes extreme confusion).
    Commented out line with method curveToPoint to put in your investigated method, appendBezierPathWithArcFromPoint. I checked on radius, not an integer but rather a float, which with hindsight makes sense on a raster because a hypotenuse is irrational and I might like to turn that triangle with Bezier bent bottom into an Apple pie (forgive the pun).
    I didn't figure the hypothenuse of 200 and 100 right triangle, but grew impatient and made a radius 200.0 to type match, taking no chances to find this alleged bug.
    I got a triangle not a pie. Oh, maybe your method didn't do anything and closePath did.
    I commented out closePath.
    I lost the red and green strokes on bottom but got a triangle fill. Plausibly fills should spill all over if they are to open objects, that's the way quickdraw opcodes work.
    Now, I doubt Apple again. Which way is this float pointing? Was the pie to curve in or out? Tried with and without closePath and got a straight triangle fill.
    Note:
    My search space is doubling because I don't have one bit facts:
    1.What is this closePath doing when the triangle fill is straight, do we have a triangle or don't we.
    2. What difference, if any, does sign of radius float make. How do I specify which way the arc curves to make an Apple pie or Apple dent.
    When my puzzlement increases like this, I need to give things a rest to get a heuristic in the search, otherwise I keep doubling up things to try and fill up my "chess board" with more than the grains of wheat or sand in the world, however that story goes.

    A heuristic comes to me in a morning vision when thinking out of the box.

    Gotta get a good nights sleep and then back at it!

    Sorry, that's the way my brain works and I am quite happily unemployed. So far it looks like appendBezierPathWithArcFromPoint is also not working.
    ;-)
    • no morning vision heuristic, ;-(
      2001-11-20 09:29:58  psheldon [View]

      Remain clueless how to guess what's going on right or wrong in this method. Miss Carolyn Rose's prose before procedure descriptions in Inside Mac, but a person can only write so much in a lifetime.
      ;-(
      She, however, did define this ordered style in what I hope our thread might evolve into the documentation and improvements.
    • thinking in box, curve out of box ;-)
      2001-11-19 22:42:06  psheldon [View]

      Lay awake and thought, what if first argument attached to first part of your method name, ...ArcFromPoint, meant to draw the arc with a compass point at that point . It didn't make sense to say append... as well as remind the point you were at to append to, so an alternate hypothesis on that argument dawned on me and seemed to have biasing evidence toward it .
      Well, setting the radius at 200.0 drew the curve with that radius and tangent to the other parts of the Bezier path outside the cliprect or whatever it is now called, but for thrills I tried other than Apple pie hypothesis radii that were too short. Now, this method is drawing an Apple dent, but, not with the compass point at the apex where I thought I had put it, but out there off cliprect in the opposite direction so as to insure tangency. I tried various floats smaller than 200.0. Negative radius drew nothing nor did fill with the apex from point.
      Summary, I got it to draw but did not confirm my alternate interpretation of the argument due to redundancy dissonance, that interpretation being I was placing a compass point. I'm still lost and maybe now ready to sleep for that heuristic rather than constantly rise with blind haymaker hypotheses.
      • first sample code and story
        2001-11-21 09:54:45  psheldon [View]

        Two hours and forty five minutes of commenting got me hot to it.
        I was, at first, frustrated that I couldn't color code the paths differently to remember who did what and then I started in my mind to grasp what was going on without color coding by commenting out certain strokes.
        The fog cleared. I always start with intense fog and then I get smart.
        I rewrote the code so I could have one place to change p1's x coordinate etc. and see what happened and confirmed your hypothesis really good in all cases except the one you gave which was only confirmed by your "robust fuzzy thinking".
        I must train in a pool doing laps now, but brief you on the results here :
        I got arcs to draw precisely from p1 to be tangent to that imaginary line as I lengthened what I called the base (line p1-p2) by moving p2 away farther. With the staging in variables I only had to change the value of float x2=...; and I saw many cases exactly confirming your hypothesis.
        When you get such confirmation, you get hot and closer to writing the prose like Carolyn Rose! You have the confidence of sufficient events and all the hidden struggles behind your writing.
        ;-)
        • tool for fluted ends of fonts, serifs (?)
          2001-11-21 12:29:22  psheldon [View]

          - (void)drawRect:(NSRect)rect {

          //define things centrally and in stages to more easily experiment
          /*
          remark :
          Below, I play with making the radius too short to join to the imaginary guide line. An extension line is drawn to the arc to the imaginary control line.
          I wish I could figure the postscript context story, as Next Step probably did a postscript port into their interface and only too well understood that stuff to be able to explain it to us newbies.
          Maybe a story about the drafting tools for hot metal type from some sad obsolete soul who can no longer use his once expensive equipment in the age of desktop publishing. The fellow I'm thinking of, his initials BB, geez I'd be scared to bring it up, but Donald Knuth might be completely inaccessible, especially at thanksgiving.
          ;-)
          Maybe safer was someone familiar, not with hot metal, but rather with a font drawing program, friend woman artist.
          I tried babbling to her. Out of the blue flew into my mind serifed fonts.
          She wasn't hot to it and couldn't respond. I thought to pass the ball to the thread.
          I have, however, since had a clear "vision" that this is correct, such a tool is used for the serif.
          Zoom up a pdf file and look at a bunch of characters and find examples! Aw heck, consider the letter R with fluted feet, this tool could draw pieces of that.
          The arguments of the method were (at first glance) otrociously named, but you can only cram so much into a short space and once you get the feeling of the tool, the words from and to make more sense and don't overload you with pronunciation, spelling or reading and "sort of get out of the way".
          ;-)
          */

          //p1 is my "base left", p2 my "base right"

          float x1=0;
          float y1=100;

          // float x2=80;
          // float x2=100;
          // float x2=120;
          // float x2=150;
          // float x2=180;
          float x2=10000;
          float y2=100;

          float xcenter=40;
          float ycenter=160;

          //note compiler forgave me forgettingt decimal point for float
          //float radius=20;// way down from 60 so won't hit, makes straight line then arc to imaginary line
          //float radius=30;// progressing up and past 60
          //float radius=40;
          //float radius=50;
          //float radius=55;
          //float radius=60;
          float radius=120;

          //lone point distinguished by not having little rect around it, the end of a NSBezierpath to append to :
          NSPoint p1 = NSMakePoint(x1, y1);

          //Will make little rects around the end points of the imaginary line :
          NSPoint p2 = NSMakePoint(x2, y2);
          NSPoint center = NSMakePoint(xcenter, ycenter);
          //NSMakeRect(x,y,w,h)
          NSRect p2Rect = NSMakeRect(x2-1.0, y2-1.0, 2, 2);
          NSRect centerRect = NSMakeRect(xcenter-1.0, ycenter-1.0, 2, 2);

          //Objects that when stroked will draw the rects
          NSBezierPath * p2Path;
          NSBezierPath * centerPath;

          //path to augment with arc and arc
          NSBezierPath * wall;
          NSBezierPath * barrier;
          //I added
          NSBezierPath * base;

          //Want to isolate what does what and couldn't color strokes differently.
          //These objects evidentally don't get the color.
          [[NSColor blackColor] set];
          p2Path = [NSBezierPath bezierPathWithRect:p2Rect];
          [p2Path stroke];

          centerPath = [NSBezierPath bezierPathWithOvalInRect:centerRect];
          [centerPath stroke];

          // Constructing the path
          //rather constructing a path amongst featuring displaying paths with the method in question
          wall = [NSBezierPath bezierPath];
          //no path to append to since
          //this moves pen with penup from last point of rect around center to start pt p1
          [wall moveToPoint:p1];
          //center is not center of circle and I go to p2(point on right and marked)
          //seems to confirm tangent, but not tangent at point p2, goes beyond.
          //how does method determine length of arc?
          [wall appendBezierPathWithArcFromPoint:center toPoint:p2 radius:radius];
          [wall stroke];

          barrier = [NSBezierPath bezierPath];
          [barrier moveToPoint:center];
          [barrier lineToPoint:p2];
          [barrier stroke];

          //my additional line
          base = [NSBezierPath bezierPath];
          [base moveToPoint:p1];
          [base lineToPoint:p2];
          [base stroke];

          }
      • happy you figured it out
        2001-11-20 22:29:03  psheldon [View]

        Now, 12:30 A.M. I'm anxious and excited to try out the code and follow your story and see if I can grasp what is going on. I'm sure happy that os 10.1 allows me to connect to my internet computer's lower os 9 appletalk and port over the sample code you give . I shall comment it (take notes on it) and read your story to get the connections going in my head. At first I can be pretty dense, so I better hold off until morning or I'll get in the wrong frame of mind to sleep. But, I'd sure like to peak at it.
        Do you know the feeling?
        • The plot thickens!
          2001-11-21 06:40:57  retro [View]

          Once I get going on something like this, I just don't want to stop. It's going to bug me all day at work today. This function brings back visions of architectural drafting in high school.

          An interesting thing I found: When you draw the arc, it conforms to the angle from which you have created. However, if you append to the arc, it does not append to the ever-floating end of the arc, but to the "toPoint:" argument (!). That means the computer will go back and connect itself, thus drawing an ugly line where none originally existed. This intuitively does not make sense, but from a computer programmer's point of view it is necessary.

          One of the weaknesses of this function is it's reliance on static points. If you want to make a continuous path, you _have_ to know that your end point is at precisely the point at which the arc becomes tangent to the second line. The second point of tangential contact is equidistant from the apex as the first point of tangential contact. Using manual drafting means, you could discover these points by drawing an arc using the apex as the center point for your compass. You could then find the arc's center by drawing two separate arcs of the desired radial length from each of the two end points, the center being at the intersection point. Then finally, you would draw the arc while carefully erasing all of the other lines.

          Unfortunately, we do not have the convenience of a compass to measure where the second point should be. Up to this point it has just been a static point. This is insufficient. We need to find a way to calculate this point and have it change automatically to accommodate the changes in the arc's radius. We need to do the same for the starting point, as I have noticed the arc does not necessarily start at our starting point, but wherever it is mathematically to do so. The starting point, fromPoint and toPoint are used as guides for arc creation but starting or ending points for subsequent path creation. I'll have to think about this one and post more later.
          • The plot thickens! So does the fluted R.
            2001-11-21 14:20:42  psheldon [View]

            second paragraph :
            You are hotter to what your wrote , is ugly line related to the line to the flute on the R end? cf tool for fluted ends of fonts, serifs (?) .
            3rd paragraph :
            Weakness might be merely for certain values or uses. A tool has a weakness for what you want, you pick up another tool. You're "the man" or artist, you choose, moment by moment. Values change. You want to make some sort of object that draws an R with flutes, you value this, if you want to draw roses, there are other tools.
            I think, because I went off on a tangent of finding the postscript context, I have some sort of hindsight you missed.
            Does my fluted R vision help you with the conceptualization?
        • Absolutely
          2001-11-21 05:34:53  retro [View]

          I was up late last night still trying to completely grasp what this function does, and I am doing so right now. I tried, for instance, to make a perfect 100x100 square, and attempted 4 iterations of this command to attempt to draw a flower-like picture. I assumed that the radius of the arcs, 50, would cause a series of half-circles to be made, but I was mistaken.

          In fact I believe that the arcs made by this function are actually quite different. The first tangent is made between the initial (appended-to) point and the "fromPoint", the second tangent is made with the "fromPoint" and the "toPoint", as if the two points defined an arbitrarily infinite line for the arc's radius to match properly. You know, its amazing - I didn't fully understand this until I started writing this reply. Trying to explain it to you brought understanding to me.

          I have uploaded a picture:
          http://homepage.mac.com/abenassi/Images/ArcAndGuide.pct

          Here is the new code, which I finally completely grasp:

          - (void)drawRect:(NSRect)rect {
          #define SIDE_LENGTH 100
          float bottom = 100;
          float left = 100;
          float top = bottom + SIDE_LENGTH;
          float right = left + SIDE_LENGTH;

          NSPoint bottomLeft = NSMakePoint(left, bottom);
          NSPoint bottomRight = NSMakePoint(right, bottom);
          NSPoint topRight = NSMakePoint(right, top);

          NSBezierPath * arc;
          NSBezierPath * guide;

          [[NSColor blackColor] set];

          // Draw the arc itself
          arc = [NSBezierPath bezierPath];
          [arc moveToPoint:bottomLeft];
          [[NSColor blackColor] set];
          [arc appendBezierPathWithArcFromPoint:topRight toPoint:bottomRight radius:60];
          [arc stroke];

          // Draw the guide from which the computer creates the arc
          guide = [NSBezierPath bezierPath];
          [guide moveToPoint:bottomLeft];
          [guide lineToPoint:topRight];
          [guide lineToPoint:bottomRight];
          [guide stroke];
          }
          • Absolutely --- ah I see two tangential
            2001-11-21 14:52:20  psheldon [View]

            Paragraph 2 :
            I hadn't seen this. Thank you. So, forcing my mind to stretch along my theory as well. You start the leg of the R on each side of the fill and pull the leg with the method to the end of the flute. I think with your direction of the end control, you have two have arguments switched to have it flute each way.
            You wrote : "Trying to explain it to you brought understanding to me".
            Finding out that writing something to explain to Rockwell Space Division, I was actually explaining it to myself was a life changing experience. In industry, you have those who move up by copying politically correct statements and believing them. People have thought that whenever someone talks to some other, someone is wasting someone else's time because one person must be learning and the other finding him a parasite. Others have thought both people are wasting time. Some supervisors are jealous of other people talking to each other because that takes "power" away from the supervisor and you should report through formal channels of command. Others brow beat you for wasting the valuable supervisors time talking to him. Should should should, all a mockery for job security in Rockwell Space Division. If you can should someone else you are holier than thou in SoCal and that works to get you job security (or, at least, that is the way a senior there explained it to me).
            My life changing experience was to go to each individual with one paragraph and ask what was the worst, most incomprehensible, sentence in that paragraph. The people, not a specialist in what I was hot to, found that very easy, even though they were astonished that I would ask them such a question. Everybody in the think tank read one of the paragraphs and picked the awful sentence and I rewrote each of those sentences. I got smart from everyone elses complaints, didn't noticeably bother them because they didn't have to understand anything just say what single sentence they least understood in a single paragraph. I cited them all!
            Analogous to Captain Kirk I hope I can continue to believe that "I don't believe in the win lose scenario", though his was the Kobyashi Maroon (sp?) "I don't believe in the no win scenario" cheat.
            You might summarize my attempted inspiration with intuition transcends formal channels of communication. Formal channels of communication are from a funny book, "The Psychology of Computer Programming" .
            Paragraph 3 :
            I saw the picture. You have remembered some lesson I forgot or know how to make a screen shot in os x. Cool. We have a new window on results we can show each other. The picture clearly illustrates the two tangent matching ends of the arc. I found the picture easy to refer to rather than rerunning the code. I then grasped the new concept you found.
            Well, now I think I should rest and watch Robin Hood Prince of Thieves with Kevin Costner.
      • I figured it out!
        2001-11-20 21:22:43  retro [View]

        I believe I have the solution. The two points passed to this method serve as a guide for an imaginary line. That is, if you drew an infinitely long line which included the two points, that line is your guide. The method attempts to draw an arc with the specified radius from the current bezier path end point to another point somewhere on this line. The arc, as you noted, will always meet at a tangent to the imaginary line, and the direction the arc travels depends on the order of the two points specified. The imaginary line is actually a vector telling the arc as to which direction to travel.

        I lack psheldon's linguistic capability to describe this as accurately as I would like, so here is some code to compile. I draw a line between the two guid points to show a segment of the imaginary line. You can see the direction of the arc come into play if you change the order in which you pass the two control points.

        - (void)drawRect:(NSRect)rect {

        NSPoint p1 = NSMakePoint(0, 100);
        NSPoint p2 = NSMakePoint(80, 100);
        NSPoint center = NSMakePoint(40, 160);
        NSRect p2Rect = NSMakeRect(79, 99, 2, 2);
        NSRect centerRect = NSMakeRect(39, 159, 2, 2);
        NSBezierPath * p2Path;
        NSBezierPath * centerPath;
        NSBezierPath * wall;
        NSBezierPath * barrier;

        [[NSColor blackColor] set];
        p2Path = [NSBezierPath bezierPathWithRect:p2Rect];
        [p2Path stroke];

        centerPath = [NSBezierPath bezierPathWithOvalInRect:centerRect];
        [centerPath stroke];

        // Constructing the path
        wall = [NSBezierPath bezierPath];
        [wall moveToPoint:p1];
        [wall appendBezierPathWithArcFromPoint:center toPoint:p2 radius:60];
        [wall stroke];

        barrier = [NSBezierPath bezierPath];
        [barrier moveToPoint:center];
        [barrier lineToPoint:p2];
        [barrier stroke];

        }

      • Thanks...
        2001-11-20 12:09:30  retro [View]

        I also thought it strange that you would need to tell the initial point from which to append a path. The documentation is poor on this method, and it is a shame that this is the first method in NSBezierPath that draws anything. People like me who are trying to start out and wrap our minds around this class are naturally going to try to use this method first. I wish I was at home so that I could try to confirm and confer our findings for this method. Later tonight I will give it a whirl.