Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 3-dimensional plotting : x, y, z axes
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
richcash




PostPosted: Fri Jul 21, 2006 4:26 pm   Post subject: 3-dimensional plotting : x, y, z axes

Can someone tell me how to plot 3d points on a 2d screen if I have (x, y, z)?
Also, I need to know how to make the screen turn. So, if the screen has turned 360 degrees, then it's back in the same spot.
If I simply use sin and cos for a circle won't it make the objects on the screen look like they're travelling on a curve?
My best attempt is to take x / z and y / z and plot those, and as I said use sin and cos to turn the screen, but this is not correct!

Any info or ideas? Thanks in advance.
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Fri Jul 21, 2006 4:33 pm   Post subject: (No subject)

The good-looking textured light-sourced bouncy fun smart and stretchy page is a good source for such things. The exact link which I think you would find useful is: plotting 3D points onto a 2D screen. Smile
Delos




PostPosted: Fri Jul 21, 2006 4:35 pm   Post subject: (No subject)

I'm going to assume that you know your way around Turing and more importantly, around trig. If you have a background in 3D maths as well (3D physics is just as good), then you're set to go.

This page will give you all the necassary theory behind converting a 3D object into its 2D projection.
First get that working, once you've done that you can start worrying about changing camera angles and such. Shouldn't be too difficult if you're programming using Classes and start with a Camera object.

That being said, use Classes! They will improve the quality of your life tremendously. This is not an easy undertaking, so best of luck with it.

Bah! [Gandalf] beat me to it...well, at least having a second person posting exactly the same links (no doubt both from Cervantes' post!) should give enough credence to that particular page...
richcash




PostPosted: Fri Jul 21, 2006 4:56 pm   Post subject: (No subject)

Thanks! That's exactly what I needed. I have the first few parts working.
The website is quite detailed except for panx, pany, and panz. What are these and what sort of values should they be?
richcash




PostPosted: Fri Jul 21, 2006 5:14 pm   Post subject: (No subject)

The first part works great!

code:
var centrex := maxx div 2
var centrey := maxy div 2
var zoom := 20
var x, y, z : array 1 .. 8 of real
var screenx, screeny : array 1 .. 8 of int

proc assign (var i1, i2, i3, i4 : real, val : int)
    i1 := val
    i2 := val
    i3 := val
    i4 := val
end assign
%SIMPLE CUBE COORDINATES
assign (x (1), x (3), x (5), x (7), 10)
assign (x (2), x (4), x (6), x (8), 20)
assign (y (1), y (2), y (5), y (6), 10)
assign (y (3), y (4), y (7), y (8), 20)
assign (z (1), z (2), z (3), z (4), 10)
assign (z (5), z (6), z (7), z (8), 15)
proc _3d
    for n : 1 .. 8
        %GIVEN CODE
        if z (n) > 0 then

            screenx (n) := round (x (n) / z (n) * zoom) + centrex

            screeny (n) := round (y (n) / z (n) * zoom) + centrey

        end if
        %END GIVEN CODE
    end for
end _3d

_3d

for n : 1 .. 8
    drawdot (screenx (n), screeny (n), 7)
end for


But I don't think this is correct?

code:
var centrex := maxx div 2
var centrey := maxy div 2
var zoom := 100
var x, y, z, newx, newy, newz : array 1 .. 8 of real
var screenx, screeny : array 1 .. 8 of int
var panx, pany, panz := 20
var posx, posy, posz : int := 100

posz := 1
proc assign (var i1, i2, i3, i4 : real, val : int)
    i1 := val
    i2 := val
    i3 := val
    i4 := val
end assign
%SIMPLE CUBE COORDINATES?
assign (x (1), x (3), x (5), x (7), 10)
assign (x (2), x (4), x (6), x (8), 20)
assign (y (1), y (2), y (5), y (6), 10)
assign (y (3), y (4), y (7), y (8), 20)
assign (z (1), z (2), z (3), z (4), 10)
assign (z (5), z (6), z (7), z (8), 20)

proc _3d
    for n : 1 .. 8
        %GIVEN CODE
        x (n) := x (n) + posx

        y (n) := y (n) + posy

        z (n) := z (n) + posz



        newx (n) := x (n) * cosd (panx) - z (n) * sind (panx)

        newz (n) := x (n) * sind (panx) + z (n) * cosd (panx)

        newy (n) := y (n) * cosd (pany) - newz (n) * sind (pany)

        z (n) := newy (n) * cosd (pany) - newz (n) * sind (pany)

        x (n) := newx (n) * cosd (panz) - newy (n) * sind (panz)

        y (n) := newx (n) * sind (panz) + newy (n) * cosd (panz)

        if z (n) > 0 then

            screenx (n) := round (x (n) / z (n) * zoom) + centrex

            screeny (n) := round (y (n) / z (n) * zoom) + centrey - 200

        end if
        %END GIVEN CODE
    end for
end _3d

_3d
for n : 1 .. 8
    drawdot (screenx (n), screeny (n), 7)
end for


This is just a quick test, I will use classes later on.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: