| Thread Closed |
Logarithmic scale problem |
Share Thread |
| Dec26-05, 09:58 AM | #1 |
|
|
Logarithmic scale problem
I am working on a homework for a programming class. We have to create a Logarithmic plot and add to it a marker when the program is running on the click of the mouse. That is NOT the problem :) , in fact, that's very simple!
My problem, however, is with the scale. When my plot is in linear scale it adds the marker right where it should. By that I mean that if I click on point (1,2) it adds my marker on (1,2). Now, when I switch to logarithmic scale, if I click on (0,0) it adds the marker on (1,1). If I click on values greater than 10, it adds the marker at the place where I clicked. But when my values are lower than 10, the marker is shifted to the right. How do I solve that problem? I already tried converting the values I get from my mouse-click event to logarithmic values and they are wrong. In fact I get negative numbers when the values are lower than 1; so the marker is shifted to the left. I am not good at all with log scales; so, please help me!! |
| Dec26-05, 11:43 AM | #2 |
|
|
The logarithm of 1 is 0, so when you click on (0,0) you are really clicking in (log 1, log 1). Anyway, you cannot have the poin (0,0) in a log scale, since log 0 = - infinity. The logarithm of a number between 0 and 1 is negative. |
| Dec26-05, 03:32 PM | #3 |
|
|
The code is in Java. We are using a library called JFreeChart to create the chart. Here is the click event where everything happens:
Code:
public void mouseClicked (MouseEvent e)
{
if (SwingUtilities.isRightMouseButton (e))
return;
if(pointerAdded)
return;
//These return the x,y position on the screen or screen location
int x = e.getX ();
int y = e.getY ();
// Translates a screen location to a Java2D point.
Point2D p = translateScreenToJava2D (new Point (x, y));
//create Plot object
XYPlot plot = getChart ().getXYPlot ();
//get the chart renderer
ChartRenderingInfo info = getChartRenderingInfo();
//The area where the clicked occured
Rectangle2D dataArea = info.getPlotInfo().getDataArea();
//Get the plot coordinates of where the event ocurrs
double xx = plot.getDomainAxis ().java2DToValue (p.getX (), dataArea, plot.getDomainAxisEdge ());
double yy = plot.getRangeAxis ().java2DToValue (p.getY (), dataArea, plot.getRangeAxisEdge ());
//Add the custom annotation
CircleDrawer cd = new CircleDrawer(
Color.RED, Color.BLACK , new BasicStroke(1.0f), null);
XYAnnotation bestBid = new XYDrawableAnnotation(
xx, yy, 11, 11, cd
);
this.renderer.addAnnotation(bestBid);
pointerAdded = true;
repaint ();
}
About what you say, you're right and I had noticed that before. Now, my question is, how do I go from (log 1, log 1) to my linear numbers so that I can get the right position? |
| Dec26-05, 04:37 PM | #4 |
|
|
Logarithmic scale problem
I just did a quick test to see what the event returns. As I click closer to 0, it results in a number sifted more and more to the right. I am only showing the x coordinate since the y have exactly the same results. Also, the resulting values are approximate since I did not zoom in close enough in the plot to click exactly on the number.
Click on Result 10 10 9 9.118812375 8 8.223735874 7 7.307858871 6 6.444623616 5 5.50047321 4 4.624704838 3 3.70626008 2 2.820675981 1 1.90761842 0 1.003834079 it looks like a function, I just don't know how to find it. I think that if I find it, I can solve my problem. Thanks |
| Dec27-05, 09:59 AM | #5 |
|
|
y = 1.1104x - 1.1234. |
| Dec28-05, 12:46 PM | #6 |
|
|
can you post the code? I have an idea, but don't know if it defeats the purpose or not.
Would flooring the result be a work around? Matt |
| Dec29-05, 02:53 AM | #7 |
|
|
|
| Thread Closed |
Similar discussions for: Logarithmic scale problem
|
||||
| Thread | Forum | Replies | ||
| Logarithmic problem | General Math | 2 | ||
| Basic Logarithmic Problem | General Math | 4 | ||
| Natural logarithmic function problem | Calculus & Beyond Homework | 7 | ||
| compactification scale versus decompactification scale | Beyond the Standard Model | 0 | ||
| Re: Higgs Particles & Scale-Invariant Metrics & Breaking Scale Symmetry | General Physics | 4 | ||