strange behavior of ggbApplet.getXcoord()

János Losonczi shared this question 1 year ago
Answered

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

Files: test.ggb

Comments (12)

photo
1

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

/BwaASV+4fTJUAAAAAElFTkSuQmCCAA==

photo
1

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

photo
1

I revoke my previous comment.

photo
1

Now I realised my real problem.

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

  • e-based logarithmic answer: -8.881784197001252e-16 (see test.ggb), instead of an
  • 10-based logarithmic answer: -8.881784197001252E-16

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?

photo
1

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


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

photo
1

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?

photo
1

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

photo
1

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.

photo
1

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

photo
1

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

photo
1

you can replace them before command

photo
1

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.

© 2019 International GeoGebra Institute