I would like to calculate distance from origin for some points. I don't know how to do that in Javascript.
If x
and y
are the co-ordinates of a point distanceFromOrigin=sqrt(x^2 + y^2)
.
So far, below is the code I could get running in HTML:
<html>
<head>
<script id="vertices">
float distanceFromOrigin;
void
main()
{
distanceFromOrigin=(x * x) +(y * y);
}
</script>
</head>
</html>
How to add a square root to the above variable distanceFromOrigin. And also is there a power function instead of doing x*x
?