How to get or calculate coordinates?

Thread Solved

Join Date: Sep 2008
Posts: 8
Reputation: JChakra is an unknown quantity at this point 
Solved Threads: 0
JChakra JChakra is offline Offline
Newbie Poster

How to get or calculate coordinates?

 
0
  #1
Jul 5th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 146
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: How to get or calculate coordinates?

 
0
  #2
Jul 5th, 2009
Draw by hand on sheet of squared paper and take coords from that?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 8
Reputation: JChakra is an unknown quantity at this point 
Solved Threads: 0
JChakra JChakra is offline Offline
Newbie Poster

Re: How to get or calculate coordinates?

 
0
  #3
Jul 5th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,813
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: How to get or calculate coordinates?

 
0
  #4
Jul 5th, 2009
Originally Posted by JChakra View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 146
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: How to get or calculate coordinates?

 
0
  #5
Jul 5th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 8
Reputation: JChakra is an unknown quantity at this point 
Solved Threads: 0
JChakra JChakra is offline Offline
Newbie Poster

Re: How to get or calculate coordinates?

 
0
  #6
Jul 6th, 2009
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.

  1. FLOWER
  2. 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
  3. Start (0,-8) , (4,-6) , (6,-7) , (4,-8) , (0,-8) Stop
  4. Start (-1,-11) , (-3,-7) , (-6,-6) , (-5,-9) , (-1,-11) Stop
  5. Start (1,-15) , (5,-11) , (8,-11) , (7,-13) , (1,-15) Stop
  6. 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
  1. GeneralPath flower = new GeneralPath();
  2. flower.moveTo(200,200);
  3. flower.lineTo(4,4); //start
  4. flower.lineTo(0,0);
  5. flower.lineTo(-3,0);
  6. flower.lineTo(-2,3);
  7. flower.lineTo(4,4);
  8. flower.lineTo(-2,7);
  9. flower.lineTo(-3,10);
  10. flower.lineTo(0,10);
  11. flower.lineTo(4,4);
  12. flower.lineTo(3,9);
  13. flower.lineTo(5,11);
  14. flower.lineTo(6,9);
  15. flower.lineTo(4,4);
  16. flower.lineTo(9,9);
  17. flower.lineTo(11,8);
  18. flower.lineTo(10,6);
  19. flower.lineTo(4,4);
  20. flower.lineTo(10,4);
  21. flower.lineTo(12,2);
  22. flower.lineTo(10,1);
  23. flower.lineTo(4,4);
  24. flower.lineTo(8,-2);
  25. flower.lineTo(7,-2);
  26. flower.lineTo(4,-3);
  27. flower.lineTo(4,4); //stop
  28. flower.lineTo(0,-8);//start
  29. flower.lineTo(4,-6);
  30. flower.lineTo(6,-7);
  31. flower.lineTo(4,-8);
  32. flower.lineTo(0,-8);//stop
  33. flower.lineTo(-1,-11);//start
  34. flower.lineTo(-3,-7);
  35. flower.lineTo(-6,-6);
  36. flower.lineTo(-5,-9);
  37. flower.lineTo(-1,-11);//stop
  38. flower.lineTo(1,-15);//start
  39. flower.lineTo(5,-11);
  40. flower.lineTo(8,-11);
  41. flower.lineTo(7,-13);
  42. flower.lineTo(1,-15);//stop
  43. flower.lineTo(4,4);//start
  44. flower.lineTo(-1,-11);
  45. flower.lineTo(2,-17);//stop

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

Please throw some lights on the problem.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 146
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: How to get or calculate coordinates?

 
0
  #7
Jul 6th, 2009
Just a guess - but maybe moveTo(...) rather tha drawTo when you want to go to a new coordinate without drawing?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 8
Reputation: JChakra is an unknown quantity at this point 
Solved Threads: 0
JChakra JChakra is offline Offline
Newbie Poster

Re: How to get or calculate coordinates?

 
0
  #8
Jul 6th, 2009
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 ?
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 16
Reputation: sincerelibran is an unknown quantity at this point 
Solved Threads: 9
sincerelibran sincerelibran is offline Offline
Newbie Poster

Re: How to get or calculate coordinates?

 
0
  #9
Jul 7th, 2009
Originally Posted by JChakra View Post
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 + ")";
}
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 146
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: How to get or calculate coordinates?

 
0
  #10
Jul 7th, 2009
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
Last edited by JamesCherrill; Jul 7th, 2009 at 8:35 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC