Re: Zooming, Bezier Paths and Affine Transforms
Re: Zooming, Bezier Paths and Affine Transforms
- Subject: Re: Zooming, Bezier Paths and Affine Transforms
- From: Henry McGilton <email@hidden>
- Date: Mon, 27 Dec 2004 08:26:05 -0800
On Dec 26, 2004, at 11:49 PM, Greg wrote:
Hi,
I am creating a graph view that allows the user to be able to zoom an
area of the x-axis only. This is because a plot can contain up to
around 10,000 samples, so to make it easier in viewing areas of the
graph I need to be able to zoom areas of it. I am having some trouble
trying to display the graph correctly. I can get the correct range of
samples to display from the user drawing a box on the graph to zoom
it, but when it comes to display it correctly, is where my problems
occur.
The steps I am using are to translate to the start of the graph area
as there is a margin for axis values and labels. I then translate the
x axis to the start of the zoomed samples, (_durationStart). I then
scale the X axis by the width and number of zoomed samples
(NSWidth(graphBounds) / (_durationEnd - _durationStart)) and the
height by the number of values in the Y axis. I then translate the
graph by the Y axis minimum value as this might not be set at 0.
I seem to have problems when I use affine transforms as my
understanding of them is very limited. I would appreciate it if
someone could recommend a book or resource on the net to help me
better understand what is happening to the co-ordinate space when I do
translations, scales and rotations. Does anyone know what I am doing
wrong fundamentally?
My book PostScript By Example contains a chapter on Transformations.
The graphics model of Cocoa is a lineal descendant of PostScript,
including path construction, colour models, and transformations.
The book is illustrated copiously with over 500 code samples plus
over 750 pictures of the results of running the code.
Chapters 12 and 13 of Cocoa Programming by Anguish, Buck, and Yacktman
also covers the use of Bezier paths and affine transforms.
Some of the developer AppKit examples contain use of affine transforms.
See BezierPathLab, CircleView, and CompositeLab. And you can download
the RoundTransparentWindow example code from the Apple Developer web
site:
http://developer.apple.com/samplecode/RoundTransparentWindow/
RoundTransparentWindow.html
Thanks,
Greg
if (_flags.showHeartRate)
{
NSAffineTransform *scale = [NSAffineTransform transform];
NSBezierPath *p = [cur objectForKey:HeartRateKey];
NSRect pathRect = [p bounds];
[scale translateXBy:NSMinX(graphBounds) yBy:NSMinY(graphBounds)];
[scale translateXBy:-_durationStart yBy:0];
My first thought is that you might want to put this translate line:
[scale translateXBy:0 yBy: - _heartRateMin];
before the scaleBy . . . code
Alternatively, you could simply compute the three translations
values ahead of time and do a single translate, and then do the
scale.
[scale scaleXBy:NSWidth(graphBounds) / (_durationEnd -
_durationStart)
yBy:NSHeight(graphBounds)/(_heartRateMax - _heartRateMin)];
Because after you do the scaleBy, any new translations are being done
in
the scaled coordinate system, assuming I understand it myself . . .
And then, before you do the concat, insert this line:
[NSGraphicsContext saveGraphicsState];
[scale concat];
[[_heartRateColor colorWithAlphaComponent:1.0 - (i / (c * 1.0))]
set];
[p setLineWidth:_heartRateStroke];
[p stroke];
And instead of using invert and concat
[scale invert];
[scale concat];
use this line:
[NSGraphicsContext restoreGraphicsState];
}
The saveGraphicsState and restoreGraphicsState methods to
NSGraphicsContext push and pop the current graphics state onto
a stack. You can nest transforms within each other by using
these calls. For those familiar with the PostScript page
description language, these are conceptually similar to
gsave and grestore.
Cheers,
........ Henry
===============================+============================
Henry McGilton, Boulevardier | Trilithon Software
Objective-C/Java Composer | Seroia Research
-------------------------------+----------------------------
mailto:email@hidden | http://www.trilithon.com
|
===============================+============================
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden