import gpdraw.*;

public class chemical
{
    public static void main(String args[])
    {
        DrawingTool pencil=new DrawingTool(new SketchPad(700, 700));
        double points[][]=new double[4][3];
        double theta=0;
        double vx=0, vy=0, vz=2;
        while(true)
        {
            points[0][0]=0;//x
            points[0][1]=1;//y
            points[0][2]=0;//z

            points[1][0]=.94281*Math.cos(theta);
            points[1][1]=-1/3;
            points[1][2]=.94281*Math.sin(theta);

            points[2][0]=.94281*Math.cos(theta+2.09439);
            points[2][1]=-1/3;
            points[2][2]=.94281*Math.sin(theta+2.09439);

            points[3][0]=.94281*Math.cos(theta+4.18879);
            points[3][1]=-1/3;
            points[3][2]=.94281*Math.sin(theta+4.18879);

            double screenx, screeny;
            for(int i=0; i<4; i++)
            {
                double x, y, z;
                x=points[i][0];
                y=points[i][1];
                z=points[i][2];

                screenx=vx+(vz-1)*(x-vx)/(vz-z);
                screeny=vy+(vz-1)*(y-vy)/(vz-z);

                pencil.up();
                pencil.move(200*screenx, 200*screeny);
                pencil.down();
                pencil.drawCircle(5);
            }
            pencil.up();
            pencil.move(200*vx/vz, 200*vy/vz);
            pencil.down();
            pencil.drawCircle(5);
            theta+=.1;
        }

    }
}

I am having trouble with this, spefically dealing with the camera.
This program uses gpdraw, http://205.173.45.43/staff/charity_purse/eric_ferrante/www/WebLessons/gpdraw/html/gpdraw/DrawingTool.html I dont know how to upload the .jar file to use it in program, but I can make a google docs if necessary.
I have a CH4 methane molecule, with the C at (0, 0, 0), and one H at (0, 1, 0). The other ones are places appropriately, with a y value of -1/3 (if I am correct). They rotate about the y-axis; only those with y-value -1/3 will change their x and z values according to the variable theta (changes by .1 radians). the variables vx, vy, vz represent tghe coordinates of the 'camera'.
My calculation is this: I construct a line between the camera and the point to be 'looked at'. I see where this line intersects the plane z=1 (simplest one), and that point's x and y values are what are put onto the screen.
(screenx=vx+(vz-1)(x-vx)/(vz-z);screeny=vy+(vz-1)(y-vy)/(vz-z); these formulas should be correct (please check them?)

My problem is this.
When I set my camera to (0, 0, 2) the central carbon appears to be coplanar with the three rotating points! This is clearly not correct, as they have a y value of -1/3. Furthermore, their y position on the screen should be changing because their plane does not pass through the camera! What is going on?

Recommended Answers

All 2 Replies

whats gpdraw?

your post is quite laborious on the eye , maybe if you 1st describe how you are trying to solve it through your program , people here can help you out better.

gpdraw is just basically a class/jar file that creates a new window and has a bunch of methods for drawing stuff on the screen, it creates a 'drawingtool' object that is much like a real life pencil.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.