Solved

Help getting a value from coordinates

Posted on 2009-03-30
2
232 Views
Last Modified: 2012-05-06
Hi Folks!

Its a late night for me an I cant figure this out.. my heads numb.

I have the following function that converts x, y values to coordinates value on a grid.
Ie with the grid width & height at 400 with 20 columns and rows the following

The attached functions convert the coordinates to an x,y value ie..

(0,0) =  (x=0, y=0)
(1,1) = (x=20,y=20)
(2,2)=(x=40,y=40)

How can I go about getting the inverse using the parameters gridWidth, gridHeight.... etc

Ie..
if the x value is between 0-20 then the x coord is 0
or between 20-40 the x coord is 1?

regards
Steve
gridWidth = 400;
gridColumns = 20;
gridHeight = 400;
gridRows = 20;
 
public static double coordToX(double coord){
    return (gridWidth / gridColumns) * coord;
}
 
public static double coordToY(double coord){
    return (gridHeight / gridRows) * coord;
}

Open in new window

0
Comment
Question by:Stephen Manderson
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 24025257
public static double XTOcoordToX(double X){
    return (gridColumns /  gridWidth) * X;
}
 
public static double YTOcoord(double Y){
    return ( gridRows / gridHeight) * Y;
}
0
 
LVL 19

Author Comment

by:Stephen Manderson
ID: 24025307
Thanks once again ozo! :) Knew it was something very simple lol
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question