aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes drawing using real world coordinates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "drawing using real world coordinates" Watch "drawing using real world coordinates" New topic
Author

drawing using real world coordinates

vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
Hi
i am loading image in browser using Swing components inside a JScrollPane. I have to draw up on this loaded image using real world coordinates.How can i do it?

Thanks in advance for replies.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Moving to our Swing forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What's a "real world coordinate"? Latitude and longitude? Translate between viewport coordinates.
vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
David Newton wrote:What's a "real world coordinate"? Latitude and longitude? Translate between viewport coordinates.


Nope
I exact problem is locating components in image of electronics boards. I will get x,y cartesian coordinates and boards images.
I succeeded in loading the image in an applet and integrated in jsp page.i am using JScrollPane to load image and placed in a boarder lay out(Center portion).

expecting reply.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Vinod, read your private messages.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

So you're asking how to scale your viewport?
vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
David Newton wrote:So you're asking how to scale your viewport?


No david.
i have the cartesian cordinates of components in borad. i want to put small mark in loaded images. I tried it,but failed to point exact location.


Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
vinod cmt wrote:I tried it,but failed to point exact location.

What exactly did you try and how have you failed? Maybe you could provide your implementation of paintComponent() method?


Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
Peter Taucher wrote:
vinod cmt wrote:I tried it,but failed to point exact location.

What exactly did you try and how have you failed? Maybe you could provide your implementation of paintComponent() method?


Yes,
i am pasting code snippets with in paintComponent()

double imgwidth=image.getWidth(null);// image is image object loaded.
double imgheight=image.getHeight(null);
double scaleX=imgwidth/boardwidth; //boardwidth is the width of the original board we calculated in mm
double scaleY=imgheight/boardheight;//boardheight is height of original board.
double x,y;
x=Double.parseDouble("X");//X is cartesian x coordinate
y=Double.parseDouble("Y");//Y is cartesian y coordinate.
y=boardheight-y;
x=x*scaleX;y=y*scaleY;
x-=20;y-=20;
Rectangle r=new Rectangle2D.Double(x,y,10,10);
g2D.draw(r);
g2D.fill(r);

But it is not locating as i expected.where is the problem?
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
1) Use code tags
2) What do you expect, and how does the result differ from your expectations? -> TellTheDetails
vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
Peter Taucher wrote:1) Use code tags
2) What do you expect, and how does the result differ from your expectations? -> TellTheDetails

Hi Taucher

Can you explain code tag? is t any Tag library?
I am putting small mark up on components with in image.But the rectangle which i drawn is little away from the components.
Can you suggest any other method ?


Thanks for reply.
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
I'm providing a small example (using code tags):

I think (because you didn't really explain it) your problem might be the scaling. You have to translate the coords and size of the rectangles the same way you scale your image.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Vinod, I asked you to read your private messages, but apparently you haven't yet. This is your second warning.
vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
Peter Taucher wrote:I'm providing a small example (using code tags):

I think (because you didn't really explain it) your problem might be the scaling. You have to translate the coords and size of the rectangles the same way you scale your image.



Hi Taucher

I am getting the x,y coordinates from CAD (PCB design people) .They were giving it in mills and i will get width,height and image of the borad.
I want draw exactly on components locations on board images loaded in jsp page.

thanks for reply.
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
1) Don't make a fullquote when you don't need one
2) TellTheDetails -> ShowSomeEffort -> Provide a SSCCE

You still didn't provide a valid problem description. What exactly are you expecting and how does the behaviour differ from your expectations (in detail!). Simply saying 'it doesn't paint where I want it to' makes no sense to anyone but you. Providing an example that shows the misbehaviour (SSCCE) might give us all the possibility to comprehend...
vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
Peter Taucher wrote:1) Don't make a fullquote when you don't need one
2) TellTheDetails -> ShowSomeEffort -> Provide a SSCCE

You still didn't provide a valid problem description. What exactly are you expecting and how does the behaviour differ from your expectations (in detail!). Simply saying 'it doesn't paint where I want it to' makes no sense to anyone but you. Providing an example that shows the misbehaviour (SSCCE) might give us all the possibility to comprehend...


Hi Taucher

I am attaching a board image and i want to draw the following components below.
cktref (x,y)
C13 (205,1150)
R1 (343,325)
R4 (292,1192)
C12 (388,334)
CR1 (976,399)
L4 (1040,1129)
C30 (790,1370)

Here x,y are in cartesian coordinates.
i plotted these components in red mark in image attached.
How it draw it exactly by loading in jsp page?



[Thumbnail for top.jpg]

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What do you mean "draw it exactly by loading in the JSP page"? Most of the red marks seem to be located correctly, no?
vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
David Newton wrote:What do you mean "draw it exactly by loading in the JSP page"? Most of the red marks seem to be located correctly, no?


Hi David

Sorry for misleading.That red marks i did it using some Image editors,not through jsp page.I did for identifying the specified components.
I have to make simillar marks on boards after loading in jsp.

Also components X ,Y are in mills.
Actual board width is 30 mm and height is 30.9 mm.

thanks for reply.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why do you have to make the marks after loading in JSP? Why not before? I don't understand why the coordinate transformation is difficult; can you explain what's actually happening? Where are the marks ending up? Can you post *just* the coordinate transformation code?
vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
David Newton wrote:Why do you have to make the marks after loading in JSP? Why not before? I don't understand why the coordinate transformation is difficult; can you explain what's actually happening? Where are the marks ending up? Can you post *just* the coordinate transformation code?

Ya, i did it already in above post.



thanks for replay.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What are lines 7 and 8 supposed to do?
vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
David Newton wrote:What are lines 7 and 8 supposed to do?


Hi David

Lines 7 and 8 are parsing X,Y coordinate getting from CAD system.
For example C13 (205,1150), here x=205 and y=1150.

Thanks for replay.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Could you post the real code for that section of code then?
vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
:rolleyes:
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Okay, don't, but don't expect much help if you're not willing to explain what your code is doing--the code you posted is trying to parse two strings as doubles. If that isn't your real code, then how do I know the *rest* of it is real?

Why do you subtract 20? Why do you subtract y from the boardheight? Why are you doing more beyond getting the "scaled" x, y coordinates? You didn't even say where the origin is for the board measurements, nor show where the boxes *were* being drawn so we'd know if it was something simple like different origins.

Roll your eyes all you want--but if you can't or won't provide the information asked for, or the information that's necessary, or the actual code that isn't working, I'm not sure what you expect people to do.
vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
Hi David

By parsing strings to double just i am taking x,y coordinate in cartesian coordinates. The origin of the board is always left side bottom only.
That is why i am subtract y from boardheight..subtracting 20 for the sake of drawing rectangle around the components,through calculation we are getting middle point of components.


Thanks for reply.


David Newton wrote:Okay, don't, but don't expect much help if you're not willing to explain what your code is doing--the code you posted is trying to parse two strings as doubles. If that isn't your real code, then how do I know the *rest* of it is real?

Why do you subtract 20? Why do you subtract y from the boardheight? Why are you doing more beyond getting the "scaled" x, y coordinates? You didn't even say where the origin is for the board measurements, nor show where the boxes *were* being drawn so we'd know if it was something simple like different origins.

Roll your eyes all you want--but if you can't or won't provide the information asked for, or the information that's necessary, or the actual code that isn't working, I'm not sure what you expect people to do.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: drawing using real world coordinates