How to rotate a line around one of its vertexes
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am making my first raycasting engine, and would like to rotate a line over an angle θ
How does one do this? Would it be possible to show me some basic C++ code or some pseudocode?
This image describes my problem:
Optional question
I decided to make all of this in graphics.h
, because it is the simplest graphics header for C/C++.
c++ algorithm geometry raycasting cartesian-coordinates
add a comment |
I am making my first raycasting engine, and would like to rotate a line over an angle θ
How does one do this? Would it be possible to show me some basic C++ code or some pseudocode?
This image describes my problem:
Optional question
I decided to make all of this in graphics.h
, because it is the simplest graphics header for C/C++.
c++ algorithm geometry raycasting cartesian-coordinates
Also interested, because cross product works only in 3 dimensions
– ishidex2
Jan 3 at 10:43
Link doesn't work, I get the image cannot be displayed.
– SPlatten
Jan 3 at 10:43
It works for me :/
– ishidex2
Jan 3 at 10:45
If you are doing linear algebra, pick a linear algebra library and express it using values of appropriate types. Then you can write code that looks like the mathsB = P + M * (A - P);
can be valid C++
– Caleth
Jan 3 at 12:08
This website can be of help to you: geomalgorithms.com
– kvantour
Jan 3 at 12:08
add a comment |
I am making my first raycasting engine, and would like to rotate a line over an angle θ
How does one do this? Would it be possible to show me some basic C++ code or some pseudocode?
This image describes my problem:
Optional question
I decided to make all of this in graphics.h
, because it is the simplest graphics header for C/C++.
c++ algorithm geometry raycasting cartesian-coordinates
I am making my first raycasting engine, and would like to rotate a line over an angle θ
How does one do this? Would it be possible to show me some basic C++ code or some pseudocode?
This image describes my problem:
Optional question
I decided to make all of this in graphics.h
, because it is the simplest graphics header for C/C++.
c++ algorithm geometry raycasting cartesian-coordinates
c++ algorithm geometry raycasting cartesian-coordinates
edited Jan 3 at 12:08
kvantour
10.8k41734
10.8k41734
asked Jan 3 at 10:40
Sir.RosticcianoSir.Rosticciano
106
106
Also interested, because cross product works only in 3 dimensions
– ishidex2
Jan 3 at 10:43
Link doesn't work, I get the image cannot be displayed.
– SPlatten
Jan 3 at 10:43
It works for me :/
– ishidex2
Jan 3 at 10:45
If you are doing linear algebra, pick a linear algebra library and express it using values of appropriate types. Then you can write code that looks like the mathsB = P + M * (A - P);
can be valid C++
– Caleth
Jan 3 at 12:08
This website can be of help to you: geomalgorithms.com
– kvantour
Jan 3 at 12:08
add a comment |
Also interested, because cross product works only in 3 dimensions
– ishidex2
Jan 3 at 10:43
Link doesn't work, I get the image cannot be displayed.
– SPlatten
Jan 3 at 10:43
It works for me :/
– ishidex2
Jan 3 at 10:45
If you are doing linear algebra, pick a linear algebra library and express it using values of appropriate types. Then you can write code that looks like the mathsB = P + M * (A - P);
can be valid C++
– Caleth
Jan 3 at 12:08
This website can be of help to you: geomalgorithms.com
– kvantour
Jan 3 at 12:08
Also interested, because cross product works only in 3 dimensions
– ishidex2
Jan 3 at 10:43
Also interested, because cross product works only in 3 dimensions
– ishidex2
Jan 3 at 10:43
Link doesn't work, I get the image cannot be displayed.
– SPlatten
Jan 3 at 10:43
Link doesn't work, I get the image cannot be displayed.
– SPlatten
Jan 3 at 10:43
It works for me :/
– ishidex2
Jan 3 at 10:45
It works for me :/
– ishidex2
Jan 3 at 10:45
If you are doing linear algebra, pick a linear algebra library and express it using values of appropriate types. Then you can write code that looks like the maths
B = P + M * (A - P);
can be valid C++– Caleth
Jan 3 at 12:08
If you are doing linear algebra, pick a linear algebra library and express it using values of appropriate types. Then you can write code that looks like the maths
B = P + M * (A - P);
can be valid C++– Caleth
Jan 3 at 12:08
This website can be of help to you: geomalgorithms.com
– kvantour
Jan 3 at 12:08
This website can be of help to you: geomalgorithms.com
– kvantour
Jan 3 at 12:08
add a comment |
3 Answers
3
active
oldest
votes
You want:
B = P + M * (A - P)
Where M
is a 2D rotation matrix:
M = | cos(ϴ) -sin(ϴ) |
| sin(ϴ) cos(ϴ) |
In C++ it could be written as:
float c = cos(theta), s = sin(theta);
float dx = ax - px, dy = ay - py;
float bx = px + c * dx - s * dy;
float by = py + s * dx + c * dy;
add a comment |
One simple algorithm:
- Move the circle
-P
, so thatP
is at (0, 0). - Rotate
A
by the angle by multiplying it by the rotation matrix. - Move the circle
P
to restore its original position.
All these three steps can be done using one 3x3 matrix multiplication.
add a comment |
The scalar product of two vectors have the following property:
vec(PA) . vec(PB) = rho cos theta
Taking the definition of our two vectors:
vec(PA) = (x_a-x_p, y_a-y_p)
vec(PB) = (x_b-x_p, y_b-y_p)
We can get:
(x_a-x_p)(x_b-x_p) + (y_a-y_p)(y_b-y_p) = rho cos theta (1)
Since PA=PB, we also have:
(x_a-x_p)^2 + (y_a-y_p)^2 = (x_b-x_p)^2 + (y_b-y_p)^2 (2)
From (1)
and (2)
you can derive x_b
and y_b
with some arithmetic autopilot.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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
},
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%2fstackoverflow.com%2fquestions%2f54020650%2fhow-to-rotate-a-line-around-one-of-its-vertexes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You want:
B = P + M * (A - P)
Where M
is a 2D rotation matrix:
M = | cos(ϴ) -sin(ϴ) |
| sin(ϴ) cos(ϴ) |
In C++ it could be written as:
float c = cos(theta), s = sin(theta);
float dx = ax - px, dy = ay - py;
float bx = px + c * dx - s * dy;
float by = py + s * dx + c * dy;
add a comment |
You want:
B = P + M * (A - P)
Where M
is a 2D rotation matrix:
M = | cos(ϴ) -sin(ϴ) |
| sin(ϴ) cos(ϴ) |
In C++ it could be written as:
float c = cos(theta), s = sin(theta);
float dx = ax - px, dy = ay - py;
float bx = px + c * dx - s * dy;
float by = py + s * dx + c * dy;
add a comment |
You want:
B = P + M * (A - P)
Where M
is a 2D rotation matrix:
M = | cos(ϴ) -sin(ϴ) |
| sin(ϴ) cos(ϴ) |
In C++ it could be written as:
float c = cos(theta), s = sin(theta);
float dx = ax - px, dy = ay - py;
float bx = px + c * dx - s * dy;
float by = py + s * dx + c * dy;
You want:
B = P + M * (A - P)
Where M
is a 2D rotation matrix:
M = | cos(ϴ) -sin(ϴ) |
| sin(ϴ) cos(ϴ) |
In C++ it could be written as:
float c = cos(theta), s = sin(theta);
float dx = ax - px, dy = ay - py;
float bx = px + c * dx - s * dy;
float by = py + s * dx + c * dy;
answered Jan 3 at 10:53


HolyBlackCatHolyBlackCat
17.2k33568
17.2k33568
add a comment |
add a comment |
One simple algorithm:
- Move the circle
-P
, so thatP
is at (0, 0). - Rotate
A
by the angle by multiplying it by the rotation matrix. - Move the circle
P
to restore its original position.
All these three steps can be done using one 3x3 matrix multiplication.
add a comment |
One simple algorithm:
- Move the circle
-P
, so thatP
is at (0, 0). - Rotate
A
by the angle by multiplying it by the rotation matrix. - Move the circle
P
to restore its original position.
All these three steps can be done using one 3x3 matrix multiplication.
add a comment |
One simple algorithm:
- Move the circle
-P
, so thatP
is at (0, 0). - Rotate
A
by the angle by multiplying it by the rotation matrix. - Move the circle
P
to restore its original position.
All these three steps can be done using one 3x3 matrix multiplication.
One simple algorithm:
- Move the circle
-P
, so thatP
is at (0, 0). - Rotate
A
by the angle by multiplying it by the rotation matrix. - Move the circle
P
to restore its original position.
All these three steps can be done using one 3x3 matrix multiplication.
answered Jan 3 at 10:51
Maxim EgorushkinMaxim Egorushkin
90.1k11104192
90.1k11104192
add a comment |
add a comment |
The scalar product of two vectors have the following property:
vec(PA) . vec(PB) = rho cos theta
Taking the definition of our two vectors:
vec(PA) = (x_a-x_p, y_a-y_p)
vec(PB) = (x_b-x_p, y_b-y_p)
We can get:
(x_a-x_p)(x_b-x_p) + (y_a-y_p)(y_b-y_p) = rho cos theta (1)
Since PA=PB, we also have:
(x_a-x_p)^2 + (y_a-y_p)^2 = (x_b-x_p)^2 + (y_b-y_p)^2 (2)
From (1)
and (2)
you can derive x_b
and y_b
with some arithmetic autopilot.
add a comment |
The scalar product of two vectors have the following property:
vec(PA) . vec(PB) = rho cos theta
Taking the definition of our two vectors:
vec(PA) = (x_a-x_p, y_a-y_p)
vec(PB) = (x_b-x_p, y_b-y_p)
We can get:
(x_a-x_p)(x_b-x_p) + (y_a-y_p)(y_b-y_p) = rho cos theta (1)
Since PA=PB, we also have:
(x_a-x_p)^2 + (y_a-y_p)^2 = (x_b-x_p)^2 + (y_b-y_p)^2 (2)
From (1)
and (2)
you can derive x_b
and y_b
with some arithmetic autopilot.
add a comment |
The scalar product of two vectors have the following property:
vec(PA) . vec(PB) = rho cos theta
Taking the definition of our two vectors:
vec(PA) = (x_a-x_p, y_a-y_p)
vec(PB) = (x_b-x_p, y_b-y_p)
We can get:
(x_a-x_p)(x_b-x_p) + (y_a-y_p)(y_b-y_p) = rho cos theta (1)
Since PA=PB, we also have:
(x_a-x_p)^2 + (y_a-y_p)^2 = (x_b-x_p)^2 + (y_b-y_p)^2 (2)
From (1)
and (2)
you can derive x_b
and y_b
with some arithmetic autopilot.
The scalar product of two vectors have the following property:
vec(PA) . vec(PB) = rho cos theta
Taking the definition of our two vectors:
vec(PA) = (x_a-x_p, y_a-y_p)
vec(PB) = (x_b-x_p, y_b-y_p)
We can get:
(x_a-x_p)(x_b-x_p) + (y_a-y_p)(y_b-y_p) = rho cos theta (1)
Since PA=PB, we also have:
(x_a-x_p)^2 + (y_a-y_p)^2 = (x_b-x_p)^2 + (y_b-y_p)^2 (2)
From (1)
and (2)
you can derive x_b
and y_b
with some arithmetic autopilot.
edited Jan 3 at 13:42
answered Jan 3 at 10:57


YSCYSC
25.7k657112
25.7k657112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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.
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%2fstackoverflow.com%2fquestions%2f54020650%2fhow-to-rotate-a-line-around-one-of-its-vertexes%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
Also interested, because cross product works only in 3 dimensions
– ishidex2
Jan 3 at 10:43
Link doesn't work, I get the image cannot be displayed.
– SPlatten
Jan 3 at 10:43
It works for me :/
– ishidex2
Jan 3 at 10:45
If you are doing linear algebra, pick a linear algebra library and express it using values of appropriate types. Then you can write code that looks like the maths
B = P + M * (A - P);
can be valid C++– Caleth
Jan 3 at 12:08
This website can be of help to you: geomalgorithms.com
– kvantour
Jan 3 at 12:08