in reply to drawing 3D rectangle in Perl/Tk

If you want/need to stick with Perl/Tk...then you need to to matrix math. With the right matrix you can re-position, rotate, re-size an object by applying the matrix to each point of the object. Then finally there's a matrix to project each 3d point onto a 2d plane (your viewing canvas.) Now that you have all the co-ordinates in 2d, just draw it with Perl/Tk. Instead of using matrices you can also simulate some (limited) 3d objects or objects in 3d world. A rectangle spinning on Y axis is fairly easy: in a loop first contract corner x co-ordinates (slightly contracting y co-ordinates for one edge to show perspective) until it becomes a line (x co-ordinates for all corners are same), then expand the x co-ordinates to original (increasing slightly y co-ordinates of opposite edge of rectangle.) Chris

Replies are listed 'Best First'.
Re: Re: drawing 3D rectangle in Perl/Tk
by pg (Canon) on Mar 29, 2003 at 23:20 UTC
    "3D rectangle" is kind of vague. If he used terminologies like cube, tetrahedron, dodecahedron etc, I would be 100% percent sure about what he meant, but "3d rectangle"...

    There is a chance that he might actually mean a rectangle with certain relief, and 3D alike, for example, a Tk button created like this:
    $mw->Button(relief => "sunken");
    is 3D alike.

    If this is what he meant, what he really want is simply 2D shapes with "shadows". If this is the case, then much less maths is needed, and more importantly one needs a sharp sense of colors.