Game design equation (Two variables(multiple two variables) and one Result (for every case)) how to make the...
$begingroup$
I tried to solve this using multiple methods but i couldn't figure it out.
i don't know what to use in order to solve this
basically i have an input x and x2
Heading
when x = 1 and x2 = 1 Y = 45
when x = 1 and x2 = -1 Y = 315
when x = -1 and x2 = 1 Y = 135
when x = -1 and x2 = -1 Y = 225
when x = 0 and x2 = 1 Y = 90
when x = 0 and x2 = -1 Y = 270
when x = 1 and x2 = 0 Y = 360
when x = -1 and x2 = 0 Y = 180
To explain it more i want an equation that when ever i input x ,x2 values in it i get the same y value.
Ii don't know if its feasible or if math can deal with that type of situation but i believe that somehow there should be a way to make that equation
I tried to use Excel to solve this as a regression but it didn't work
analysis regression
$endgroup$
add a comment |
$begingroup$
I tried to solve this using multiple methods but i couldn't figure it out.
i don't know what to use in order to solve this
basically i have an input x and x2
Heading
when x = 1 and x2 = 1 Y = 45
when x = 1 and x2 = -1 Y = 315
when x = -1 and x2 = 1 Y = 135
when x = -1 and x2 = -1 Y = 225
when x = 0 and x2 = 1 Y = 90
when x = 0 and x2 = -1 Y = 270
when x = 1 and x2 = 0 Y = 360
when x = -1 and x2 = 0 Y = 180
To explain it more i want an equation that when ever i input x ,x2 values in it i get the same y value.
Ii don't know if its feasible or if math can deal with that type of situation but i believe that somehow there should be a way to make that equation
I tried to use Excel to solve this as a regression but it didn't work
analysis regression
$endgroup$
$begingroup$
If this is for game design, maybe just manually code a function with an if statement to find these values for you? If there is an element of continuity, then can you graph what that would look like?
$endgroup$
– stuart stevenson
Jan 20 at 8:32
$begingroup$
Thanks but i don't want to code it i coded it all ready i want to know if our knowledge in math can be powerful enough to create something in one line rather than coding it in 20 or so, plus i want to know because i face problems like these a lot of times and i end up coding a solution for a problem that could have been solved mathematically
$endgroup$
– Dia Eid
Jan 20 at 8:36
add a comment |
$begingroup$
I tried to solve this using multiple methods but i couldn't figure it out.
i don't know what to use in order to solve this
basically i have an input x and x2
Heading
when x = 1 and x2 = 1 Y = 45
when x = 1 and x2 = -1 Y = 315
when x = -1 and x2 = 1 Y = 135
when x = -1 and x2 = -1 Y = 225
when x = 0 and x2 = 1 Y = 90
when x = 0 and x2 = -1 Y = 270
when x = 1 and x2 = 0 Y = 360
when x = -1 and x2 = 0 Y = 180
To explain it more i want an equation that when ever i input x ,x2 values in it i get the same y value.
Ii don't know if its feasible or if math can deal with that type of situation but i believe that somehow there should be a way to make that equation
I tried to use Excel to solve this as a regression but it didn't work
analysis regression
$endgroup$
I tried to solve this using multiple methods but i couldn't figure it out.
i don't know what to use in order to solve this
basically i have an input x and x2
Heading
when x = 1 and x2 = 1 Y = 45
when x = 1 and x2 = -1 Y = 315
when x = -1 and x2 = 1 Y = 135
when x = -1 and x2 = -1 Y = 225
when x = 0 and x2 = 1 Y = 90
when x = 0 and x2 = -1 Y = 270
when x = 1 and x2 = 0 Y = 360
when x = -1 and x2 = 0 Y = 180
To explain it more i want an equation that when ever i input x ,x2 values in it i get the same y value.
Ii don't know if its feasible or if math can deal with that type of situation but i believe that somehow there should be a way to make that equation
I tried to use Excel to solve this as a regression but it didn't work
analysis regression
analysis regression
asked Jan 20 at 8:25
Dia EidDia Eid
102
102
$begingroup$
If this is for game design, maybe just manually code a function with an if statement to find these values for you? If there is an element of continuity, then can you graph what that would look like?
$endgroup$
– stuart stevenson
Jan 20 at 8:32
$begingroup$
Thanks but i don't want to code it i coded it all ready i want to know if our knowledge in math can be powerful enough to create something in one line rather than coding it in 20 or so, plus i want to know because i face problems like these a lot of times and i end up coding a solution for a problem that could have been solved mathematically
$endgroup$
– Dia Eid
Jan 20 at 8:36
add a comment |
$begingroup$
If this is for game design, maybe just manually code a function with an if statement to find these values for you? If there is an element of continuity, then can you graph what that would look like?
$endgroup$
– stuart stevenson
Jan 20 at 8:32
$begingroup$
Thanks but i don't want to code it i coded it all ready i want to know if our knowledge in math can be powerful enough to create something in one line rather than coding it in 20 or so, plus i want to know because i face problems like these a lot of times and i end up coding a solution for a problem that could have been solved mathematically
$endgroup$
– Dia Eid
Jan 20 at 8:36
$begingroup$
If this is for game design, maybe just manually code a function with an if statement to find these values for you? If there is an element of continuity, then can you graph what that would look like?
$endgroup$
– stuart stevenson
Jan 20 at 8:32
$begingroup$
If this is for game design, maybe just manually code a function with an if statement to find these values for you? If there is an element of continuity, then can you graph what that would look like?
$endgroup$
– stuart stevenson
Jan 20 at 8:32
$begingroup$
Thanks but i don't want to code it i coded it all ready i want to know if our knowledge in math can be powerful enough to create something in one line rather than coding it in 20 or so, plus i want to know because i face problems like these a lot of times and i end up coding a solution for a problem that could have been solved mathematically
$endgroup$
– Dia Eid
Jan 20 at 8:36
$begingroup$
Thanks but i don't want to code it i coded it all ready i want to know if our knowledge in math can be powerful enough to create something in one line rather than coding it in 20 or so, plus i want to know because i face problems like these a lot of times and i end up coding a solution for a problem that could have been solved mathematically
$endgroup$
– Dia Eid
Jan 20 at 8:36
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
First of all, if you are asking how to find an angle given 2 coordinates, in vast majority of languages, there is a function atan2(y,x)
(or with similar name) that allows you to pass coordinates and get the value of the angle:
$$
Y=frac{180}{pi}mathop{mathrm{atan2}}(x_2,x_1).
$$
If we insist we want integer number from $1$ to $360$, we can add modulus shift:
$$
Y = mathrm{rem}left(left[frac{180}{pi}mathop{mathrm{atan2}}(x_2,x_1)-1right], 360right)+1.
$$
In C it would be translated as ((int)round(180/PI*atan2(x2,x1)-1) % 360)+1
If we do not want trigonometric function for suchsimple problem and also do not want to use precalculated array, we can go like this.
You can represent your data in a table $A_{ij}$, where $i,j=-1,0,1$:
$$
A=45 left(
begin{array}{ccc}
5 & 4 & 3 \
6 & cdot & 2 \
7 & 8 & 1 \
end{array}
right)
$$
All numbers except 8 can be represented as a bilinear interpolation of the corners:
$$
Y'=4-2x_2-x_1x_2,qquad A'=left(
begin{array}{ccc}
5 & 4 & 3 \
6 & cdot & 2 \
7 & 4 & 1 \
end{array}
right)
$$
Now we need to add 4 to the bottom 4 to get 8. We can do it with the trick $2 (x_1+1) left(1-x_2^2right)$. Finally:
$$
Y=45left(4-2x_2-x_1x_2+2 (x_1+1) left(1-x_2^2right)right)
$$
$endgroup$
$begingroup$
Sir i want first to thank you very much, then to ask you what should i learn in order to know the information that you used, you made something seemed impossible possible i never though that math can do something like that. can you please lead me to a book or topic or anything that i can start with.
$endgroup$
– Dia Eid
Jan 20 at 13:44
add a comment |
$begingroup$
There is no easy formula that gets all results in one equation, but the code can be made significantly easier than 8 cases as presented in the question. Pseudocode:
if (x==0)
{m=8, d=2}
else
{m=6+2*x, d=x}
Y=45*((m+d*x2) % 8)
The $%$-operator is the calculating the remainder of the term $m+d*x2$ modulo 8.
This will give $0$ instead if $360$ for $x=1, x2=0$, but I assume that this is OK as the design seems to be based on angles (I assume for movement).
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3080322%2fgame-design-equation-two-variablesmultiple-two-variables-and-one-result-for%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
First of all, if you are asking how to find an angle given 2 coordinates, in vast majority of languages, there is a function atan2(y,x)
(or with similar name) that allows you to pass coordinates and get the value of the angle:
$$
Y=frac{180}{pi}mathop{mathrm{atan2}}(x_2,x_1).
$$
If we insist we want integer number from $1$ to $360$, we can add modulus shift:
$$
Y = mathrm{rem}left(left[frac{180}{pi}mathop{mathrm{atan2}}(x_2,x_1)-1right], 360right)+1.
$$
In C it would be translated as ((int)round(180/PI*atan2(x2,x1)-1) % 360)+1
If we do not want trigonometric function for suchsimple problem and also do not want to use precalculated array, we can go like this.
You can represent your data in a table $A_{ij}$, where $i,j=-1,0,1$:
$$
A=45 left(
begin{array}{ccc}
5 & 4 & 3 \
6 & cdot & 2 \
7 & 8 & 1 \
end{array}
right)
$$
All numbers except 8 can be represented as a bilinear interpolation of the corners:
$$
Y'=4-2x_2-x_1x_2,qquad A'=left(
begin{array}{ccc}
5 & 4 & 3 \
6 & cdot & 2 \
7 & 4 & 1 \
end{array}
right)
$$
Now we need to add 4 to the bottom 4 to get 8. We can do it with the trick $2 (x_1+1) left(1-x_2^2right)$. Finally:
$$
Y=45left(4-2x_2-x_1x_2+2 (x_1+1) left(1-x_2^2right)right)
$$
$endgroup$
$begingroup$
Sir i want first to thank you very much, then to ask you what should i learn in order to know the information that you used, you made something seemed impossible possible i never though that math can do something like that. can you please lead me to a book or topic or anything that i can start with.
$endgroup$
– Dia Eid
Jan 20 at 13:44
add a comment |
$begingroup$
First of all, if you are asking how to find an angle given 2 coordinates, in vast majority of languages, there is a function atan2(y,x)
(or with similar name) that allows you to pass coordinates and get the value of the angle:
$$
Y=frac{180}{pi}mathop{mathrm{atan2}}(x_2,x_1).
$$
If we insist we want integer number from $1$ to $360$, we can add modulus shift:
$$
Y = mathrm{rem}left(left[frac{180}{pi}mathop{mathrm{atan2}}(x_2,x_1)-1right], 360right)+1.
$$
In C it would be translated as ((int)round(180/PI*atan2(x2,x1)-1) % 360)+1
If we do not want trigonometric function for suchsimple problem and also do not want to use precalculated array, we can go like this.
You can represent your data in a table $A_{ij}$, where $i,j=-1,0,1$:
$$
A=45 left(
begin{array}{ccc}
5 & 4 & 3 \
6 & cdot & 2 \
7 & 8 & 1 \
end{array}
right)
$$
All numbers except 8 can be represented as a bilinear interpolation of the corners:
$$
Y'=4-2x_2-x_1x_2,qquad A'=left(
begin{array}{ccc}
5 & 4 & 3 \
6 & cdot & 2 \
7 & 4 & 1 \
end{array}
right)
$$
Now we need to add 4 to the bottom 4 to get 8. We can do it with the trick $2 (x_1+1) left(1-x_2^2right)$. Finally:
$$
Y=45left(4-2x_2-x_1x_2+2 (x_1+1) left(1-x_2^2right)right)
$$
$endgroup$
$begingroup$
Sir i want first to thank you very much, then to ask you what should i learn in order to know the information that you used, you made something seemed impossible possible i never though that math can do something like that. can you please lead me to a book or topic or anything that i can start with.
$endgroup$
– Dia Eid
Jan 20 at 13:44
add a comment |
$begingroup$
First of all, if you are asking how to find an angle given 2 coordinates, in vast majority of languages, there is a function atan2(y,x)
(or with similar name) that allows you to pass coordinates and get the value of the angle:
$$
Y=frac{180}{pi}mathop{mathrm{atan2}}(x_2,x_1).
$$
If we insist we want integer number from $1$ to $360$, we can add modulus shift:
$$
Y = mathrm{rem}left(left[frac{180}{pi}mathop{mathrm{atan2}}(x_2,x_1)-1right], 360right)+1.
$$
In C it would be translated as ((int)round(180/PI*atan2(x2,x1)-1) % 360)+1
If we do not want trigonometric function for suchsimple problem and also do not want to use precalculated array, we can go like this.
You can represent your data in a table $A_{ij}$, where $i,j=-1,0,1$:
$$
A=45 left(
begin{array}{ccc}
5 & 4 & 3 \
6 & cdot & 2 \
7 & 8 & 1 \
end{array}
right)
$$
All numbers except 8 can be represented as a bilinear interpolation of the corners:
$$
Y'=4-2x_2-x_1x_2,qquad A'=left(
begin{array}{ccc}
5 & 4 & 3 \
6 & cdot & 2 \
7 & 4 & 1 \
end{array}
right)
$$
Now we need to add 4 to the bottom 4 to get 8. We can do it with the trick $2 (x_1+1) left(1-x_2^2right)$. Finally:
$$
Y=45left(4-2x_2-x_1x_2+2 (x_1+1) left(1-x_2^2right)right)
$$
$endgroup$
First of all, if you are asking how to find an angle given 2 coordinates, in vast majority of languages, there is a function atan2(y,x)
(or with similar name) that allows you to pass coordinates and get the value of the angle:
$$
Y=frac{180}{pi}mathop{mathrm{atan2}}(x_2,x_1).
$$
If we insist we want integer number from $1$ to $360$, we can add modulus shift:
$$
Y = mathrm{rem}left(left[frac{180}{pi}mathop{mathrm{atan2}}(x_2,x_1)-1right], 360right)+1.
$$
In C it would be translated as ((int)round(180/PI*atan2(x2,x1)-1) % 360)+1
If we do not want trigonometric function for suchsimple problem and also do not want to use precalculated array, we can go like this.
You can represent your data in a table $A_{ij}$, where $i,j=-1,0,1$:
$$
A=45 left(
begin{array}{ccc}
5 & 4 & 3 \
6 & cdot & 2 \
7 & 8 & 1 \
end{array}
right)
$$
All numbers except 8 can be represented as a bilinear interpolation of the corners:
$$
Y'=4-2x_2-x_1x_2,qquad A'=left(
begin{array}{ccc}
5 & 4 & 3 \
6 & cdot & 2 \
7 & 4 & 1 \
end{array}
right)
$$
Now we need to add 4 to the bottom 4 to get 8. We can do it with the trick $2 (x_1+1) left(1-x_2^2right)$. Finally:
$$
Y=45left(4-2x_2-x_1x_2+2 (x_1+1) left(1-x_2^2right)right)
$$
answered Jan 20 at 10:46
Vasily MitchVasily Mitch
2,3141311
2,3141311
$begingroup$
Sir i want first to thank you very much, then to ask you what should i learn in order to know the information that you used, you made something seemed impossible possible i never though that math can do something like that. can you please lead me to a book or topic or anything that i can start with.
$endgroup$
– Dia Eid
Jan 20 at 13:44
add a comment |
$begingroup$
Sir i want first to thank you very much, then to ask you what should i learn in order to know the information that you used, you made something seemed impossible possible i never though that math can do something like that. can you please lead me to a book or topic or anything that i can start with.
$endgroup$
– Dia Eid
Jan 20 at 13:44
$begingroup$
Sir i want first to thank you very much, then to ask you what should i learn in order to know the information that you used, you made something seemed impossible possible i never though that math can do something like that. can you please lead me to a book or topic or anything that i can start with.
$endgroup$
– Dia Eid
Jan 20 at 13:44
$begingroup$
Sir i want first to thank you very much, then to ask you what should i learn in order to know the information that you used, you made something seemed impossible possible i never though that math can do something like that. can you please lead me to a book or topic or anything that i can start with.
$endgroup$
– Dia Eid
Jan 20 at 13:44
add a comment |
$begingroup$
There is no easy formula that gets all results in one equation, but the code can be made significantly easier than 8 cases as presented in the question. Pseudocode:
if (x==0)
{m=8, d=2}
else
{m=6+2*x, d=x}
Y=45*((m+d*x2) % 8)
The $%$-operator is the calculating the remainder of the term $m+d*x2$ modulo 8.
This will give $0$ instead if $360$ for $x=1, x2=0$, but I assume that this is OK as the design seems to be based on angles (I assume for movement).
$endgroup$
add a comment |
$begingroup$
There is no easy formula that gets all results in one equation, but the code can be made significantly easier than 8 cases as presented in the question. Pseudocode:
if (x==0)
{m=8, d=2}
else
{m=6+2*x, d=x}
Y=45*((m+d*x2) % 8)
The $%$-operator is the calculating the remainder of the term $m+d*x2$ modulo 8.
This will give $0$ instead if $360$ for $x=1, x2=0$, but I assume that this is OK as the design seems to be based on angles (I assume for movement).
$endgroup$
add a comment |
$begingroup$
There is no easy formula that gets all results in one equation, but the code can be made significantly easier than 8 cases as presented in the question. Pseudocode:
if (x==0)
{m=8, d=2}
else
{m=6+2*x, d=x}
Y=45*((m+d*x2) % 8)
The $%$-operator is the calculating the remainder of the term $m+d*x2$ modulo 8.
This will give $0$ instead if $360$ for $x=1, x2=0$, but I assume that this is OK as the design seems to be based on angles (I assume for movement).
$endgroup$
There is no easy formula that gets all results in one equation, but the code can be made significantly easier than 8 cases as presented in the question. Pseudocode:
if (x==0)
{m=8, d=2}
else
{m=6+2*x, d=x}
Y=45*((m+d*x2) % 8)
The $%$-operator is the calculating the remainder of the term $m+d*x2$ modulo 8.
This will give $0$ instead if $360$ for $x=1, x2=0$, but I assume that this is OK as the design seems to be based on angles (I assume for movement).
answered Jan 20 at 10:47
IngixIngix
4,267149
4,267149
add a comment |
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3080322%2fgame-design-equation-two-variablesmultiple-two-variables-and-one-result-for%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
If this is for game design, maybe just manually code a function with an if statement to find these values for you? If there is an element of continuity, then can you graph what that would look like?
$endgroup$
– stuart stevenson
Jan 20 at 8:32
$begingroup$
Thanks but i don't want to code it i coded it all ready i want to know if our knowledge in math can be powerful enough to create something in one line rather than coding it in 20 or so, plus i want to know because i face problems like these a lot of times and i end up coding a solution for a problem that could have been solved mathematically
$endgroup$
– Dia Eid
Jan 20 at 8:36