Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Help getting a value from coordinates

Posted on 2009-03-30
Medium Priority
238 Views
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;
}
``````
0
Question by:Stephen Manderson
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 84

Accepted Solution

ozo earned 2000 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

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

## Featured Post

Question has a verified solution.

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

Have you ever thought of installing a power system that generates solar electricity to power your house? Some may say yes, while others may tell me no. But have you noticed that people around you are now considering installing such systems in their …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
###### Suggested Courses
Course of the Month5 days, 20 hours left to enroll