Solved

Help getting a value from coordinates

Posted on 2009-03-30
2
229 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
Comment Utility
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
Comment Utility
Thanks once again ozo! :) Knew it was something very simple lol
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now