Comments and answers for "Reverse of this function?"
http://answers.unity.com/questions/1546961/reverse-of-this-function.html
The latest comments and answers for the question "Reverse of this function?"Comment by Benjames on Benjames's comment
http://answers.unity.com/comments/1547433/view.html
Okay that code didn't work as well as I thought it was. So I ended up ditching the "catlike coding" code snippet and went with normalizing the grid coordinates to make my sphere. With the combination of a code snippet from Bunny83's link called DeSpherify and my last code snippet I was able to achieve what i was looking for....I thinkWed, 29 Aug 2018 04:23:39 GMTBenjamesComment by Benjames
http://answers.unity.com/comments/1547317/view.html
So here is a code snippet of what I am settling on, it's not super accurate. "$$anonymous$$ost of the time is close enough"
public int getSlotfromNorm(Vector3 s, int gridSize, ref int l, ref int j) {
float yangle = $$anonymous$$athf.Atan2(-s.z, -s.x) * $$anonymous$$athf.Rad2Deg;
float xangle = $$anonymous$$athf.Atan2(-s.z, -s.y) * $$anonymous$$athf.Rad2Deg;
float zangle = $$anonymous$$athf.Atan2(-s.x, -s.y) * $$anonymous$$athf.Rad2Deg;
int type = 0;
if (yangle > 45 && yangle < 135 && xangle > 45 && xangle < 135) {//zpos 4
j = (int)(((yangle - 45f) / 90f) * gridSize);
l = (int)(((xangle - 45f) / 90f) * gridSize);
type = 4;
}
if (yangle > -135 && yangle < -45 && xangle > -135 && xangle < -45) {//zneg 5
j = (int)((($$anonymous$$athf.Abs(yangle) - 45f) / 90f) * gridSize);
l = (int)((($$anonymous$$athf.Abs(xangle) - 45f) / 90f) * gridSize);
type = 5;
}
if (yangle > -45 && yangle < 45 && zangle > 45 && zangle < 135) { //xpos 0
j = (int)(((yangle - 45f) / -90f) * gridSize);
l = (int)(((zangle - 45f) / 90f) * gridSize);
type = 0;
}
if ((yangle > 135 || yangle < -135) && zangle > -135 && zangle < -45) { //xneg 1
j = (int)(((yangle - 135f) / 90f) * gridSize);
if (yangle < 0) {
j = (int)(((yangle +225) / 90f) * gridSize);
}
l = (int)((($$anonymous$$athf.Abs(zangle) - 45f) / 90f) * gridSize);
type = 1;
}
if ((zangle > 135 || zangle < -135) && (xangle > 135 || xangle < -135)) { //yneg 3
l = (int)(((zangle - 135f) / 90f) * gridSize);
if (zangle < 0) {
l = (int)(((zangle + 225f) / 90f) * gridSize);
}
j = (int)(((xangle - 135f) / 90f) * gridSize);
if (xangle < 0) {
j = (int)(((xangle + 225f) / 90f) * gridSize);
}
type = 3;
}
if ((zangle > -45 && zangle < 45) && (xangle > -45 && xangle < 45)) { //ypos 2
l = (int)(((zangle - 45f) / -90f) * gridSize);
j = (int)(((xangle - 45f) / -90f) * gridSize);
type = 2;
}
return (type);
}Tue, 28 Aug 2018 18:09:20 GMTBenjamesComment by Benjames
http://answers.unity.com/comments/1547019/view.html
Yeah it's from the catlike coding tutorial on cube sphere.
I made an array of the vertices of the sphere. Six 2d grids, if that makes sense?
Anyways I'm trying to make it relatively easy to edit the sphere and splats maps in unity editor.
I need or want a way to convert worldspace vector into array slots.
Thanks for the reference bunny83 .
[edit] In hindsight I should't of worded my question like that. I think I am going to find a "close enough" way using angles to find the slots in the array.
So far I can separate the six sides with cases.
Lets say I make the grid's dimensions 90x90 and find the angle between each vertices on one axis.
Its almost 1 degree difference each time but not consistently.
I bet there is some sort of relationship, like a ratio, between the "angle of vertices" and the "middle of the grid"Tue, 28 Aug 2018 02:55:21 GMTBenjamesComment by Bunny83 on Bunny83's comment
http://answers.unity.com/comments/1547001/view.html
This method is an alternative cube to sphere mapping with less distortion than just normalizing a point on the cube surface. You can find more about [that here][1].
<br>
Though i don't think there's an easy solution for this. Since the mapping for a single coordinate involves all 3 input coordinates you most likely need a case split anyways. [Just normalizing the coordinates][2] is much simpler for both way conversion
[1]: https://catlikecoding.com/unity/tutorials/cube-sphere/
[2]: https://answers.unity.com/questions/764203/reverse-spherifying-a-cube.htmlTue, 28 Aug 2018 01:40:39 GMTBunny83Comment by JVene
http://answers.unity.com/comments/1546978/view.html
@Benjames I don't yet recognize the formula from code, so can you identify what this grid_norm actually calculates?Mon, 27 Aug 2018 23:43:58 GMTJVene