# strange behavior of ggbApplet.getXcoord()

Dear All,

I work on an applet with JS, which should draw Penrose kites and darts. Now it's in test phase, and I faced with a strange behavior of the ggbApplet.getXcoord() command. I create dozens of points, and get their X coordinate with the command above. The majority of the data are right, but some of them has an absolutely wrong value, eg.: instead of 0 (zero) it's value is -8.88E-016.

For the sake of simplicity I cleaned my applet from all needless steps, there are only those commands in the script, which can illustrate this behavior.

You can see G, H and K points, every one's X coordinate is 0. These values are apparently good ones.

I checked the values with X() function, the result of course is the same.

But in those cases where the X coordinate of the point is 0, the ggbApplet.getXcoord() command in my applet gives nonsense data, and I don't know why.

Those points which don't have 0 X coordinate works well.

Can anybody help?

test.ggb is attached.

Best regards

JL

it seems to me that G has not xCoord=0. if you want coincidence you must do a little rounding in the values

You are right, but I believe it it is not the cause of this behavior.

I revoke my previous comment.

Now I realised my real problem.

It is, that ggbApplet.getXcoord() command gives me an:

How can I change this behavior of ggbApplet.getXcoord() command?

Or filter X coordinates, and convert e-based to 10-based logarithm? Are there built-in functions, or commands in GG for this purpose?

It is a 10-based exponent. That's the JavaScript syntax (small e not big E)

http://www.java2s.com/Tutor...

Maybe the definition of my problem was not correct, I try to redefine it.

I take the coordinates of point G (as it was originally), and create two points with them: TestePoint and TestEPoint

ggbApplet.evalCommand("TestePoint = (-8.881784197001252e-16, -5)"); // small e

ggbApplet.evalCommand("TestEPoint = (-8.881784197001252E-16, -5)"); // big E

Position of TestEPoint is, what I expect, it is the same as point G's.

But I can't explain position of TestePoint (see the attached test-2.ggb).

Could you explain?

java uses e for syntax but GG uses E. evalCommand is a javascript that sends -8.881784197001252e-16 to GG then GG reads -8.881784197001252 e - 16 being e the number e

This is my problem.

I read a coordinate with ggbApplet.getXcoord() command.

It returns a coordinate with "e" syntax, then when I use the return value to draw a point, GG do NOT put the point to the expected position (see TestePoint and TestEPoint). Position of TestePoint is absolutely wrong, and TestEPoint is good. I suppose it would be very useful to use the same syntax when reading a coordinate of a point and when using the coordinate of a point. See the attached test-2.png file to see the difference between the two syntax.

I'm sorry, I didn't attache it.

As mathmagic said: JavaScript uses e, GeoGebra uses E

If you type 1e2 into GeoGebra then you get a different answer to what you get in JavaScript as e is interpreted as 2.71828... in GeoGebra. That's expected.

If you use ggbApplet.evalCommand() you need to use E. If you use ggbApplet.setValue() / setCoords() / getXcoord() etc you need to use e

you can replace them before command

Dear All,

when I started this topic, I hoped there is a way to get a "synch" (in the using e and E) between getXcoord and evalCommand commands. Of course I was thinking about filtering e and replace it to E, but I didn't want to make more complex my script. Now you persuaded me that the way as these commands work, are accepted by the community.

Thank you for your help.

Loading...Comments have been locked on this page!