Calculate The object angle(face) having two points? [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
C++, I want calculate the angle of the direction of the two points.
Here is a picture which shows the two points and the direction of how to get the angle of the direction?
p1 - start point. p2 - direction point. me need direction angle(facing?) from p1 to p2

#include <cmath>
// ...
double angle = atan2(p2.y - p1.y, p2.x - p1.x);
// ...
If you want to, you can also make sure that p1 != p2, because if it is then you'll get a domain error.

Related

smooth out corners of a 3-point line strip [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a line strip defined by 3 points, each having an x and y coordinate.
I'm trying to smooth out the middle (point 2) corner as shown in the picture below:
the gray line is the original line strip and the black one is the smoothed-out one.
The smoothed out area should be constant across multiple values (as in it is not dependent on length of the line between p1 and p2 or p2 and p3).
I've originally been using bezier curves and a simple spline, however that did not do the trick since the smooth curve was obviously not same across multiple values.
How can I do this?
Pick 2 points on each line that are the same distance to the corner. On those points draw two lines at right angles to the lines you already have (normal vectors pointing bottom left). They will cross at a point which will be the center of a circle, part this circle will then be the smoothed corner.

How to rotate an QGraphicsPixmapItem in Qt [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to rotate an image in Qt. If you try this game, you can easily see how the arrow is rotating:
https://www.friv.com/z/games/killcovid19/game.html?Desktop-x-x-w-x-x-xx
Assuming my image is in a QGraphicsPixmapItem, how should I make it rotate?
First, you need to set the rotation point (bottom-right/left in your case)
void QGraphicsItem::setTransformOriginPoint(qreal x, qreal y)
And then perform a rotation around the transform point
void QGraphicsItem::setRotation(qreal angle)

Finding the visible area of a point [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
There's a triangle and a point lying outside it. We need to find the summary length of triangle sides that are visible from the point.
In this case the answer is AB+BC.
As input there are coordinates of the points.
So the question is how to solve it in C++?
P.S. In my opinion we need to find ρ(P;each of the points) and watch if this distance intersect with any of the triangle's sides. Then choose the two farthest points, which met the condition, and find the sum of the side(s).
Let's define an order for the triangle vertices. Let it be counter-clockwise. Your triangle is ACB (clockwise order would be ABC).
The point sees an edge if it's located in the right semi-plane that the edge defines.
This formula:
res = (y2 - y1)*(px - x1) - (x2 - x1)*(py - y1)
gives info about what semi-plane is (px,py) relative to (x1,y1)-(x2,y2) segment. Just get the sign of res.
You analize the three segments of the triangle an get those that the point is on the right side.
Choosing the other order changes the sign.

3D Vector Field Plot [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am creating an Electromagnetic field simulator and I am using Qt3D to plot cuboids.The output should be the same input cuboid but with different color distribution indicating the magnetic field at each point but I can't figure how to plot it this way with various colors.
Input (2 intersecting cuboids):
Output should be similar to this:

How to move gun projectile in state line [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have spawn point of projectile and I have to move it in state line direction but I don't know the destination point. So what formula or concept I will have to write to go in state line of projectile.
Suppose spawn point is (4,5) so it should go towards the direction (-4,-5), for any coordinate value.
Thanks in advance
given some x you find y using the two point formula:
y = y1 + (x-x1)*(y2-y1)/(x2-x1)
except when x2==x1
Alternatively, for a given y you get x:
x = x1 + (y-y1)*(x2-x1)/(y2-y1)
except when y2==y1
So, you have
y= 5.0 + (x+4.0)*(8.0)/(10.0)
http://en.wikipedia.org/wiki/Linear_equation