# Javascript get radius of a circle?

mcrieger shared this question 10 months ago

Hello,

I build a little interactive applet with some javascript in the update function.

I just want to color a set of circles depending on their radius. I tried getValue("c") which should return a double value, but its only returning NaN. When I use getValueString("c") it returns the circular equation, but this is really bad for comparison.

Is there no way to compare the circles?

moritz

1

with

```var ocommand=ggbApplet.getCommandString(objStr);
var odefinition=ggbApplet.getDefinitionString(objStr);```
you get center then

`var oradius=Distance(center, c)`

2

Also consider dynamic colors that don't need scripting.

You can add a condition to display a certain colour, depending on the radius of the corresponding circle.

https://wiki.geogebra.org/e...

1

Try:

`ggbApplet.evalCommandCAS("Numeric(Radius(c))")`
but why not direct in the circle-object in properties/extended

1

Oh I didnt noticed the dynamic colors panel. Thanks! :)

But I still miss the possiblity to change color, when I use the condition I only can make the object dissapear, not changing the color, do I miss something?

I also tried the JavaScript Approach rami suggest, but then geogebra freezes for seconds and I did not get updated values each time I change my construction.

Thanks for further help

1

Red:cos(r)

Green:abs(sin(r))

Blue:r-floor(r)

opacity:0.5

you can use all functions but better with functions with range [0,1]

1

Maybe I should elaborate my usecase even more

This is my https://ggbm.at/jYzzf93z construction. What I try to visualize is:

Find the smallest circle of the right small circles = r min and compare it with the circle rg. If rg < rmin colorize rmin green otherwise red. Atm I tweaked this logic for the red circle, using two circles one appears when the other dissapears...

It is not possible to put this complex logic in the small inputfield for dynamic colors.

2

delete e_1

you have not used dynamics colors. only red/green colors for two circles

see now the colors of d_1

the value true equal than 1, false equal to 0

Files: foro.ggb
2

I'm not sure it's what you are looking for.

Solution with lists and list-commands (see manual) and dynamic color

Note: only one object has a (simple) condition for dynamic-color

1

sorry it took me so long! I didn't realize that I could simply use the different conditions in the same dynamic color to get the result I was looking for. Thank you very much for your patience!