| | |
How to get or calculate coordinates?
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 8
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Jan 2008
Posts: 3,813
Reputation:
Solved Threads: 501
•
•
•
•
Call me stupid mate but I did not get it
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/MathS...rve/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.
•
•
Join Date: Apr 2008
Posts: 972
Reputation:
Solved Threads: 146
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.
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.
•
•
Join Date: Sep 2008
Posts: 8
Reputation:
Solved Threads: 0
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.
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
Am I missing any functions for 'start' and 'stop'.?
Please throw some lights on the problem.
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.
Java Syntax (Toggle Plain Text)
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
of the flower is missing mate. *puzzled*
here is the Java code for the flower
Java Syntax (Toggle Plain Text)
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.
•
•
Join Date: Sep 2008
Posts: 8
Reputation:
Solved Threads: 0
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 ?
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 ?
•
•
Join Date: Mar 2009
Posts: 16
Reputation:
Solved Threads: 9
•
•
•
•
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.
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 + ")";
}
}
•
•
Join Date: Apr 2008
Posts: 972
Reputation:
Solved Threads: 146
Hi sincerelibran. Nice code, but it looks like its duplicating the existing Point class in the Java API
http://java.sun.com/j2se/1.4.2/docs/...awt/Point.html
http://java.sun.com/j2se/1.4.2/docs/...awt/Point.html
Last edited by JamesCherrill; Jul 7th, 2009 at 8:35 am.
![]() |
Similar Threads
- More of a math problem (Java)
- object for an array (Java)
- Java Maze Problem (Java)
- Displaying Image and Text in Java 2D (Java)
- xy-rotation problem (Game Development)
- how to calculate the distence ? (Visual Basic 4 / 5 / 6)
- Frames of Pictures (C++)
Other Threads in the Java Forum
- Previous Thread: consuming a webservice
- Next Thread: Trouble with area
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working







