Comments (15)
that's caused by undefined values in the Point object, I think. The code base is absolute shit.
from hyperbolic-canvas.
@DozenalFTW The current version of Point.isIdeal()
only calls Point.getEuclideanRadius()
, which I believe will properly avoid circular calls like that. Do you know how old your version is?
from hyperbolic-canvas.
@DozenalFTW Did you call the Point constructor directly, passing it an options hash? It's not clear in the documentation, but this is not recommended. Use the factory methods instead:
Point.givenCoordinates(x, y)
Point.givenEuclideanPolarCoordinates(euclideanRadius, angle)
Point.givenHyperbolicPolarCoordinates(hyperbolicRadius, angle)
Point.givenIdealAngle(angle)
The constructor requires that specific combinations of attributes be present in the options hash, but doens't actually check to make sure that it has an appropriate combination. I was able to reproduce your results with new Point({ angle: 1 }).getEuclideanRadius()
, or new Point({ angle: 1, hyprbolicRadius: 1 }).getEuclideanRadius()
(note the spelling mistake).
I apologize for the state of the documentation. Making things like this more clear is one of the next steps.
from hyperbolic-canvas.
I also used player.center.distantPoint(speed, ang);
, where player.center
is a Point
.
I also used the variable Point.CENTER
.
I don't recall using new Point
...
Here's every single time I use Point
:
var Point = window.Point || window.HyperbolicCanvas.Point;
this.center = Point.givenCoordinates(x, y);
return Line.givenTwoPoints(A, B).hyperbolicDistance();
(came up in my search forPoint
)var mousePoint = Point.givenCoordinates(mouseCoords.x, mouseCoords.y)
if (player.center.equals(Point.CENTER)) return;
var d2c = player.center.distaceFromCenter();
(looked suspicious)
player.center = Point.givenHyperbolicPolarCoordinates(d2c, player.center.angle())
var pt = Point.givenHyperbolicPolarCoordinates(speed, ang);
var pt = player.center.distantPoint(speed, ang);
(came up in the search)
** This is just too much, after here there's nothing new- I also use
Point.CENTER
a few times
I wonder if some other function is creating the loop. Let me check.
from hyperbolic-canvas.
I was going to write the long post when I found the entire problem.
Point.givenCoordinates = function (x, y) {
return new Point({ x: x, y: y });
};
is faulty.
Here's another long post with a bunch of code.
Point.prototype.getEuclideanRadius = function () { if (typeof this._euclideanRadius === 'undefined') { if (typeof this._x === 'undefined' || this._y === 'undefined') { if (this.getHyperbolicRadius() === Infinity) { this._euclideanRadius = 1; } else { this._euclideanRadius = (Math.exp(this.getHyperbolicRadius()) - 1) / (Math.exp(this.getHyperbolicRadius()) + 1); } } else { this._euclideanRadius = Math.sqrt( Math.pow(this.getX(), 2) + Math.pow(this.getY(), 2) ); } if (Math.abs(this._euclideanRadius - 1) < 1e-6) { this._euclideanRadius = 1; } } return this._euclideanRadius; };So it seems to only call
this.getHyperbolicRadius()
if it's not initialized correctly. OK...Point.prototype.getHyperbolicRadius = function () { if (typeof this._hyperbolicRadius === 'undefined') { if (this.isIdeal()) { this._hyperbolicRadius = Infinity; } else { this._hyperbolicRadius = 2 * Math.atanh(this.getEuclideanRadius()); } } return this._hyperbolicRadius; };You're calling
this.isIdeal
:Point.prototype.isIdeal = function () { return this._euclideanRadius === 1 || this._hyperbolicRadius === Infinity || this.getEuclideanRadius() === 1; };
There have been some changes...
Point.CENTER
is nowPoint.ORIGIN
andPoint.prototype.distantPoint
is now.hyperbolicDistantPoint
.
from hyperbolic-canvas.
I've been renaming things a lot over the past month. It's bad practice for an API, but that's why there's no release yet. Point.CENTER
was renamed to Point.ORIGIN
on the 1st of April, but Point.isIdeal
was not added until the 18th of April. How is it that both exist in the same version?
When you call Point.givenCoordinates(mouseCoords.x, mouseCoords.y)
, are the mouseCoords
corrected for the width of the canvas? I don't think this could cause the problem you're having, but you should use Canvas.at
to convert coordinates on the page to a Point
.
If you can tell me the values on the Point
that causes the recursion, I'll test in the latest version. It's probably best to update, regardless. You'll have to rewrite your code to use the updated functions, but a lot has been fixed since the 1st of April.
from hyperbolic-canvas.
What exactly is wrong with Point.givenCoordinates
?
from hyperbolic-canvas.
- I changed
Point.CENTER
toPoint.ORIGIN
in my actual code. mouseCoords
is the Euclidean coordinates of the hyperbolic point your mouse is on. (If your mouse is in the center,mouseCoords
is{x: 0, y: 0}
. It's a plain object, not aPoint
.- All I know is that they are within the plane... as your mouse and player circle move, the points change.
- It doesn't initialize the values of
_isIdeal
,_euclideanRadius
, or_hyperbolicRadius
. It just inits_x
and_y
.
from hyperbolic-canvas.
- Okay. Maybe I'll allow both.
- How did you calculate the correct coordinates of the mouse without using
Canvas.at
? A few things are happening there: the plane is flipped vertically so that positive-y corresponds to "up"; the center of the canvas, rather than the top left, is made to correspond to (0, 0); and the Euclidean radius of the canvas is made to correspond to 1. Do yourmouseCoords
reflect all of those changes? - So the
_x
and_y
of anyPoint
on the plane should be less than 1 (as should_x * _x + _y * _y
). - That's intentional. The other values are meant to be calculated as needed. Do you see where I might have missed a check for undefined values?
from hyperbolic-canvas.
(2) I'm actually using a different system for rendering. I wanted an up-close view that only shows a certain Euclidean-rectangle-slice of the disk at once. But I'm confident my code works — it was working before April...
(4) Well, somehow the isIdeal
, getEuclideanRadius
, and getHyperbolicRadius
are linked into an infinite loop. I could send my entire code, but...
The stack of functions is so long I can't see where it's getting called on my end. Only chance is to use a bunch of try
commands and catch the line it happened on.
from hyperbolic-canvas.
Found out the problem is in here:
var dst = random(1, 3.9);
var ø = random(360);
var pt = Point.givenHyperbolicPolarCoordinates(dst, ø);
var radius = random(0.08, 0.3);
critters.push(new Critter(pt.x, pt.y, radius));
The Critter
constructor, stripped of everything I know isn't the problem:
// The Euclidean point that is the hyperbolic center
this.center = Point.givenCoordinates(x, y);
// but a HYPERBOLIC radius.
this.radius = r;
this.circle = Circle.givenHyperbolicCenterRadius(this.center, this.radius);
x
and y
come directly from a real legit Point
.
from hyperbolic-canvas.
pt.x
and pt.y
are undefined. Use pt.getX()
and pt.getY()
.
from hyperbolic-canvas.
But why not just pass pt
to the Critter
constructor? It should be identical to the new one that is created, aside from floating point errors.
from hyperbolic-canvas.
Fixed it, thanks!!
from hyperbolic-canvas.
Let me know if you create something interesting, and I'll link to it when I redo the site.
from hyperbolic-canvas.
Related Issues (12)
- Polygons not rendering correctly HOT 2
- how would I divide a polygon to triangles? HOT 4
- are hexagon tessellations possible in hyperbolic geometry? HOT 11
- [Question] How to deal with polar coordinates? HOT 2
- Are the units off? HOT 10
- rendering bug when I add fancy graphics HOT 33
- bug: polygons can't have a vertex of (0,0) HOT 1
- math problem with wrap around HOT 3
- Line object is too vague HOT 1
- distantPoint problem HOT 15
- how would I check if hyperbolic 2 lines intersect? HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hyperbolic-canvas.