Dear mates, I am am frustrated and bored to learn how to get or calculate coordinates data for Java Graphic API.

for ex the GeneralPath 's function curveTo() takes 6 parameters namely x1,y2,x2,y2,x3,y3.I put some random coordinates data
into these function and got a crap drawing. :(

I want to create stunning drawing by hand-coding.I see people
have done good geometric drawing such as a car,home, a human and
space shuttle etc by using these functions(curveTo,
moveTo,lineTo,drawpoly).Please tell me how to get or calculate coordinates data.

Recommended Answers

All 12 Replies

Draw by hand on sheet of squared paper and take coords from that?

Call me stupid mate but I did not get it :P

How on earth can I get coordinates from a piece of paper ?

I never heard of this trick before please explain. :)

Call me stupid mate but I did not get it :P

How on earth can I get coordinates from a piece of paper ?

I never heard of this trick before please explain. :)

The odds of you being able able to draw a Bezier Curve by hand on paper are pretty low, unless you are a far better artist than I am, which you probably are, since most people are. I think James is suggesting you use graph paper and look at the (x, y) coordinates of all the points. I'm sure there's software out there. An applet I made might help a tad, but I didn't program it to show the coordinates of the points, even though it lets you place them.

http://www.derekscswebsite.com/MathStuff/BezierCurve/index.html

It'll at least let you create some interesting curves and see what they look like, but again, it doesn't show the actual points. I suppose I should update it so it does. If you're using curveTo, to use my applet, press "Quadratic", then "Place Points", then place three points on the screen, then check or uncheck the two boxes as you wish. For a smoother curve, choose more iterations. Then press "Play".

Anyway, it's all done using Bezier Curves, and I'm sure there are much better programs out there than mine, so google is your friend there.

OK, I wasn't expecting anyone to draw perfect Bezier curves by hand, but my point was serious. Coordinates are just a count of units across/down, and squared paper gives you those for free. Freehand drawing gives you two things - a rough set of coordinates to use as a starting point, and an understanding of where coorinates need to be the same, or increase in a predictable pattern, or whatever.
This is just a specific case of a more general point - it's too easy to leap into program writing before you really understand the problem and its solution, and a quick paper simulation can sometimes be the fastest way to understand both.
Anyway, end of sermon.

Well , you guys were right about that.It's working for me the way
you told how this is done.But.. the problem is how to convert these real world (paper coordinates) to Java coordinates system.Maybe there is api available to get done this job.

However ,you guys have almost solved this problem but I want
to put forward another question regarding the coordinates.
Here is what I got for drawing a flower.

FLOWER
Start (4,4) , (0,0) , (-3,0) , (-2,3) , (4,4) , (-2,7) , (-3,10) , (0,10) , (4,4) , (3,9) ,(5,11) , (6,9) , (4,4) , (9,9) , (11,8) , (10,6) , (4,4) , (10,4) , (12,2) , (10,1) ,(4,4) , (8,-2) , (7,-5) , (4,-3) , (4,4) Stop
Start (0,-8) , (4,-6) , (6,-7) , (4,-8) , (0,-8) Stop
Start (-1,-11) , (-3,-7) , (-6,-6) , (-5,-9) , (-1,-11) Stop
Start (1,-15) , (5,-11) , (8,-11) , (7,-13) , (1,-15) Stop
Start (4,4) , (-1,-11) , (2,-17) Stop

After I wrote codes for the above flower , I only see the half of the drawing and it does not look like a flower.Some parts
of the flower is missing mate. *puzzled*

here is the Java code for the flower

GeneralPath flower = new GeneralPath();
  flower.moveTo(200,200); 
  flower.lineTo(4,4); //start
  flower.lineTo(0,0);
  flower.lineTo(-3,0);
  flower.lineTo(-2,3);
  flower.lineTo(4,4);
  flower.lineTo(-2,7);
  flower.lineTo(-3,10);
  flower.lineTo(0,10);
  flower.lineTo(4,4);
  flower.lineTo(3,9);
  flower.lineTo(5,11);
  flower.lineTo(6,9);
  flower.lineTo(4,4);
  flower.lineTo(9,9);
  flower.lineTo(11,8);
  flower.lineTo(10,6);
  flower.lineTo(4,4);
  flower.lineTo(10,4);
  flower.lineTo(12,2);
  flower.lineTo(10,1);
  flower.lineTo(4,4);
  flower.lineTo(8,-2);     
  flower.lineTo(7,-2);
  flower.lineTo(4,-3);
  flower.lineTo(4,4); //stop
  flower.lineTo(0,-8);//start
  flower.lineTo(4,-6);
  flower.lineTo(6,-7);
  flower.lineTo(4,-8);
  flower.lineTo(0,-8);//stop
  flower.lineTo(-1,-11);//start
  flower.lineTo(-3,-7);
  flower.lineTo(-6,-6);
  flower.lineTo(-5,-9);
  flower.lineTo(-1,-11);//stop
  flower.lineTo(1,-15);//start
  flower.lineTo(5,-11);
  flower.lineTo(8,-11);
  flower.lineTo(7,-13);
  flower.lineTo(1,-15);//stop
  flower.lineTo(4,4);//start
  flower.lineTo(-1,-11);
  flower.lineTo(2,-17);//stop

Am I missing any functions for 'start' and 'stop'.?

Please throw some lights on the problem. :)

Just a guess - but maybe moveTo(...) rather tha drawTo when you want to go to a new coordinate without drawing?

Yes mate , moveTo(...) does the job but I did not get
the expected result.Maybe I should try some other function
such as drawline(..) or drawpolygon(..).

Flash and Java both have same coordinates system.When I get coordinates from any drawing in flash and put into Java, I get
different shapes surprisingly.

Why is that ? I thought Flash could save me the trouble so I tried
it but it made me more frustrated. :(

How to translate flash coordinates to Java coordinates ?

Dear mates, I am am frustrated and bored to learn how to get or calculate coordinates data for Java Graphic API.

for ex the GeneralPath 's function curveTo() takes 6 parameters namely x1,y2,x2,y2,x3,y3.I put some random coordinates data
into these function and got a crap drawing. :(

I want to create stunning drawing by hand-coding.I see people
have done good geometric drawing such as a car,home, a human and
space shuttle etc by using these functions(curveTo,
moveTo,lineTo,drawpoly).Please tell me how to get or calculate coordinates data.

Dear Friend,
Never get frustrated while doing programming. Do one thing. Check this

/**
 * Coordinate.java - 
 *   Class that represents an x,y coordinate.
 *
 * @author Grant William Braught
 * @author Dickinson College
 * @version 11/10/2000
 */

class Coordinate {

    private int x;
    private int y;

    /**
     * Construct a new Coordinate from an X and Y
     * coordinate.
     *
     * @param initX the X coordinate.
     * @param initY the Y coordinate.
     */
    public Coordinate(int initX, int initY) {
    x = initX;
    y = initY;
    }

    /**
     * Get the X coordinate of the Coordinate.
     *
     * @return the X coordinate.
     */
    public int getX() {
    return x;
    }

    /**
     * Get the Y coordinate of the Coordinate.
     *
     * @return the Y coordinate.
     */
    public int getY() {
    return y;
    }

    /** 
     * Translate the position of the Coordinate by 
     * a specified amount.
     *
     * @param dx the offset in the X direction.
     * @param dy the offset in the Y direction.
     */
    public void translate(int dx, int dy) {
    x = x + dx;
    y = y + dy;
    }

    /**
     * Generate a String representation of the Coordinate.
     *
     * @return a String representation of the Coordinate.
     */
    public String toString() {
    return "(" + x + "," + y + ")";
    }
}

Below is what I got from Java but expected a flower. :(

[img]http://img18.imageshack.us/i/flowera.jpg/[/img]

As to Flash ,Since Java and Flash both have same coordinates
system , I should have no problem in creating the shape but
I am getting the messed up result. :(

If you were me , what would be your strategy to draw shapes in
Java?

Looks 60-70% right to me. Presumably just a few messed-up coordinates.
I would store the coordinates as data, rather than embed them into the code - I'd use a Vector of Points. I'd hold those in a simple text file, and just read it into the Vector, so it would be easy to edit the data. Then I'd have a simple loop that looped thru the Points drawing 1 segment at a time. For testing I'd put a bit extra in the loop so it sent the coodinates to System.out, then waited for a CR before plotting that point. Like that I could step thru the drawing 1 point at a time and see exactly which coords were wrong.
If I wanted to get clever I'd write a little JPanel that I could click on, and the Mouse handler would add the points where I clicked to the Vector of points, then write it all to the text file.

thanks for your time and programming tricks James. :)
The problem was the lineTo function which is , I believe , is not
suitable for creating polygons as we have the functions such
as drawline(..) and drawpolygon(..) for that. :)

Regarding Flash , It's true that both Java and Flash have
same coordinates system but the way Flash show the
coordinates in the property box is unclear to me.Using Flash
for this kinda job is not a good idea.

Well , the problem has been solved. :)

thanks again for your precious time. :)

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.