Skip

Help with 2D transforms in ellipse drawing algorithm
September 1, 2014 11:02 AM   Subscribe

I'm trying to draw a 3D ellipse with a 2.5D graphics engine (Core Animation layers) which allow me to only compose my ellipse with line segments that must be moved into place using rotations and translations. I'm having trouble with the order of operations and can't get it to draw properly. Any graphics gurus or game programmers out there who can help me?

Here's an image describing my current approach.

For each segment in the ellipse polygon, I'm first creating a line segment with the correct length, then translating it to the point P1, then rotating the point by the PI/2-theta, but this is clearly not working.

It's been 10 years since I took a graphics class in university, can someone please jog my memory as to what I'm doing wrong?
posted by krunk to Computers & Internet (7 answers total) 1 user marked this as a favorite
 
sorry, PI/2 + theta, not -.
posted by krunk at 11:07 AM on September 1


I recommend posting your question to Stack Overflow. Be sure to add the code snippet you have now, along with a drawing of what it makes, and what you expect.
posted by Mr. Six at 11:43 AM on September 1


Why don't you just draw an ellipse in a single layer, then use a CATransform3D to skew it appropriately? Ellipses

Alternatively, you could implement the parametric form of the ellipse in a stepwise fashion.
posted by Maecenas at 11:43 AM on September 1 [1 favorite]


I'm not particularly familiar with Core Animation, but I've written my share of low-level OpenGL and a tiny bit of Cocoa. Moral: take my input with a grain of salt because I'm not really a Mac App guy.

I'm looking at the Core Animation reference right now, and it looks like this tool is more designed to move existing graphic assets around, moreso than draw arbitrary things. You might do better to draw your ellipse using Cocoa drawing APIs and then animate it, if needed, using Core Animation. Honestly, though, if your interface requires a nice-looking ellipse in lots of different orientations/sizes/major-minor axes, you might just want to keep drawing it using Cocoa, without diving into Core Animation.
posted by Alterscape at 11:44 AM on September 1


I accidentally solved it myself!

I was cleaning up the code to post it on Stack Overflow, deleted a bunch of cruft to get it to a readable state, ran it and lo and behold – it worked perfectly!

See the results here.

This is accomplished using CATransformLayers, for those who are interested. I'll post the code on GitHub wants.
posted by krunk at 11:54 AM on September 1 [1 favorite]


It typically is easier for me to work this out by rotating and then translating. Rotation is usually defined as being around an axis that goes through the origin, so if you translate something away from the origin and then rotate, it's going to move somewhat (to me) less intuitively.
posted by jjwiseman at 2:48 PM on September 1


Sorry, here's the result.

Thanks for all your suggestions!
posted by krunk at 5:17 PM on September 1


« Older My partner would like to try P...   |  I will be driving between appr... Newer »

You are not logged in, either login or create an account to post comments



Post