advertisement

Article:
  Introduction to Cocoa Graphics, Part 2
Subject:   Absolutely
Date:   2001-11-21 05:34:53
From:   retro
Response to: happy you figured it out

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];
}


1 to 1 of 1
  1. Absolutely --- ah I see two tangential
    2001-11-21 14:52:20  psheldon [View]

1 to 1 of 1