How do i check if the follow is a right angled triangle?
I have:
A = 5
B = 1
C = ?
How do i know if this IS or ISNT a right angle?
please help!
You cannot. Triangle cannot be fully defined by only lengths of two sides.
However, you can say that if you had a triangle with sides a and b, in order for it to be a right angled triangle, it has to hold true that c^2 = a^2 + b^2
Related
I want to determine if a point from another point on a circle in the left section or in the right section. (left & right just a matter of sign interpretaton). For that I have calculated the cross product of those two points for creating the normal vector.
So the problem which I am facing is how I can interpret the normal as an scalar which has a sign which indicates whether its in the right or in the left half of the circle.
I have created a gif as for illustration (C' is just the animated point C):
My idea was to add all values within the vector v. For instance:
v = (0.16, 0.1, -0.2)
vSum = v.x + v.y + v.z = 0.06
result = sign(vSum) = 1
o = (-0.16, -0.1, 0.2)
oSum = o.x + o.y + o.z = -0.06
result = sign(oSum) = -1
unfortunately this does only work if the circle is static and does not rotate. If its rotating the sign changes so my result is flipped which leads to reversed left and right sites. And the dot product results positive values only, but this is a value which doesnt changes while rotating the circle. Maybe this is something which can help me ?
I assume, your cross product is the following:
c = cross(p - circle center, reference - circle center)
Then you can take the dot product with the circle normal to get the sign:
sign(dot(c, circle normal))
I'm trying to guide the player to the last enemy on the field, via having an icon on the edge of the screen pointing towards the last enemy outside the screen.
The screen is the rectangle, the player is the point within the rectangle, and the enemy is the point outside of the rectangle.
Example
The solutions I can think of are finding which side will be intersected (Which I'm not sure how to do correctly, but I imagine first involves finding if it will be intersecting on vertical or horizontal sides) and then using a linear equation to find the x or y. Or, you could use a line-line-intersection method on each side, but as the screen rect never changes, this seems a little overkill.
I've got my first solution working on paper for one test case, but can't get it working at all with in Unity.
Does anyone have a solution or could push me in the right direction? Thanks a lot.
Let's rectangle edges have equation
X = XLeft
Y = YBottom
X = XRight
Y = YTop
Player-enemy vector
D = (D.X, D.Y) = (E.X - P.X, E.Y - P.Y)
if D.X is positive, consider intersection with right edge (otherwise with left)
P.X + t * D.X = XRight
if D.Y is positive, consider intersection with top edge (otherwise with bottom)
P.Y + u * DY.Y = YTop
Solve equation for t and u. If u is less than t, intersection with horizontal edge goes first, and find X-coordinate of intersection with expression
XInt = P.X + u * D.X
I'm a little lost on the math aspect if what I need to do.
I have 3 points: Point A, Point B, Point C.
I need to find out if point C is on the line segment from Point A to Point B. But... the caveat is that I at the same time need to make the line "wider" from Point A to B.
I'm guessing I need to first create a bounding box that surrounds A->B? Then check if I'm within the bounding box?
How do I go about creating that box..
A and B can negative or positive on the grid, and the "distance" of the box is changeable as well.
I'm hoping this picture illustrates it better. The distance is the total given, so half would go 1 direction, half the other.
Even if I can just get those 4 points of the box, I can do the simple check to see if C is within.
Define u = normalize(b - a) and v = (-u.y, u.x).
Your point c is inside the line segment from a to b of width w if and only if both of the following hold:
0 <= dot(c - a, u) <= length(b - a)
abs(dot(c - a, v)) < w / 2
You have to (web picture with another point names P0=A, P1=B, P=C):
1) make orthogonal projection of C onto AB line (point D)
2) find distance CD and check if it is less than half-width
3) check that D lies between A and B (inside the segment)
for 2: distance d = |AC x uAB| - norm of cross product of AC vector and unit direction vector uAB = AB/|AB|
for 3: true if DotProduct(AC, AB) >= 0 and DotProduct(BC, BA) >= 0
Here you have all necessary formulas https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
First you find shortest distance btw point C and the line and check that it is less equal that width/2. Then you find coordinates of point D - closest to C point on the line and check that this point is between A and B. Than can be done by checking that distance(A,D) + distance(B,D) == distance( A,B )
I have a rectangle that has had a rotation applied. I know the rotation angle, and the top left and bottom right coordinates.
My question is, how do I calculate the dimensions of the rectangle, given these three pieces of information?
If your rotation is in terms of a center point on the rectangle, first you have to get the TL and BR relative to that origin.
Let A,B,C,D be the four vertices TL,TR,BR,BL.
You are trying to find TR and BL which would be B and D.
B_x = C_x*Cos(a) - A_y*Sin(a)
B_y = C_x*Sin(a) + A_y*Cos(a)
Likewise
D_x = A_x*Cos(a) - C_y*Sin(a)
D_y = A_x*Sin(a) + C_y*Cos(a)
Think about what they would be before the rotation. You would just use components of A and C to define B and D. The above just comes from multiplying that by the rotation matrix. Where a is the angle.
If the rotation has already been applied to A and B then get the original points before the rotation which is simply the transpose of the rotation matrix:
A'_x = A_x*Cos(a) + A_y*Sin(a)
A'_y = -A_x*Sin(a) + A_y*Cos(a)
Likewise for C
Then use A' and C' in the first set of equations to find the resulting points with rotation.
If you are just interested in length and width, A' and C' will suffice:
width = C'_x - A'_x
Height = A'_y - C'_y
I'm trying to figure out how to find a point along a line (half way, to be precice).
I need this to put a particle emitter in the correct location to leave a smoke-trail after bullets.
I've got point A and point C. Point A is the barrel-muzzle, and point C is found using ray-cast. Now, in order to put the emitter in the right location I need to find point D. How do one do this? I attached a picure to make it more visual.
No, I could not attach the picture, but here's a link.
Thanks in advance.
-Pimms
If your point is half way along a line between two points then you can just average their x and y co-ordinates to get the x and y for the midpoint (works in any number of dimensions).
If you want a point a certain proportion (ie 1/10th) along then you would do 1/10th of one point plus 9/10th of the other point.
In your example Point D is mid way between point A and C. This means the co-ordinates of D would be:
X = (0+10)/2 = 5
Y = (0+7)/2 = 3.5
Do I get you right? D is halfway between A and C ?
Solution:
D = (A + C) / 2
or:
D.x = (A.x + C.x) / 2
D.y = (A.y + C.y) / 2