Knowing the value of tan α, how to find the angle?
In a right triangle, given the tangent tan α (opposite side/adjacent side), find the angle α?
I'm trying to loop through each value and compare, but I think this is different from the real data.
Every language I'm familiar with has an arctan function that will give you the corresponding angle for a tangent value. If you have the actual lengths that produce the tangent (as in your triangle example) there should also be an arctan2 function that takes both values and puts the angle in the correct quadrant.
Related
I would like to find the curvature at a given point on a 3D b-spline.
I believe that I want to use the derivatives of the spline at that point to calculate the curvature at that point but I do not understand how.
I have defined a 3D bspline (taken from SolidWorks (where it came from is not relevant )) in geomdl. I can evaluate any point on the spline using Curve.evaluate_single(). This appears to work correctly. I have verified the returned points against the SolidWorks model so I assume I have implemented the bspline in nurbs correctly.
I need to find the radius at a various points along this curve. From my Google searching I think that I want to use Curve.derivatives() to calculate the instantaneous curvature at that point. But I do not understand how to get the results of Curve.derivatives() into a radius.
So below is the result of Curve.derivatives(SomePointOnPath,4):
[ [74.66019681782404, 131.77035668055586, 19.88498274391211],
[-2719.7097781710354, -598.8099790539873, -711.5032638750225],
[-5384.519486543373, 1273.8662545231637, 19431.220551950217],
[93757.48746982217, -22247.397114396095, 31343.52746776864],
[0.0, 0.0, 0.0]]
By taking points a small step either side of this point I have calculated the radius at this point to be about 409 ( Solving for radius of a circle given 3 points )
I do not understand what the results from Curve.derivatives() are telling me.
(the first tuple is the coordinates of the point, beyond that I am lost)
I expect the radius at this particular point to be about 409.
My fundamental question is two parts:
What are the results telling me. What do they mean.
How do I use these result to calculate the radius at this point.
The radius of curvature of a curve can be computed as |C'|^3/|C' X C"| where C' and C" are the first and the 2nd derivative vectors, X is the cross product operator and |.| is the vector's magnitude. So, you will need the first and the 2nd derivatives at that point to compute the radius of curvature.
Curve.derivatives(SomePointOnPath,4) returns the first 4 derivatives of the curve and the 0-th derivative is the position of the point on the curve. Therefore, the first derivative is [-2719.7097781710354, -598.8099790539873, -711.5032638750225] and the 2nd derivative is [-5384.519486543373, 1273.8662545231637, 19431.220551950217]. So, we can use these two vectors to do our computation and obtain a radius of curvature 408.9176414, which is close to your estimated value 409.
On a side note, you can simply pass '3' as the 2nd argument to Curve.derivatives() as the 3rd derivatvie vector has no use in the computation of radius of curvature.
In a 2D plane, I have 2 objects (A and B) with 2 coordinates. Their centers are A(xA, yA) and B(xB, yB) (and C(xC, yC)=C(xB, yA) as AC parallel to the OX line and BC is perpendicular on AC). I can manipulate the rotation of an object and I have access to all usual math operations and can use degrees and radians.
I researched but I couldn't find anything explained in detail.
I also tried using the math formula with arccos formula as follows:
I tried to calculate the distance from A to B (AB) using the Pythagoras theorem, then calculate A to C (AC), then calculate cos(angle)=AC/AB, so the final angle to which I would need to rotate object A towards B is arccos(AC/AB).
Problem is this sounds insanely buggy as you can probably get a lot of digits and ruin everything.
So how can I do this? Please explain mathematically. Thanks!
The simplest way to find the angle between two points is to take their arctangent (a.k.a. inverse tangent). You were on the right track with using cosine, but tangent simplifies the process by not requiring the distance between the points to be known.
As such, you'll want to use an atan2 function in your choice of language. The C# Math.Atan2, for example:
double angle = Math.Atan2(B.Y - A.Y, B.X - A.X);
Note: This particular function returns the angle in radians.
Do you want to rotate object A towards B with C like center of the rotation ?
If it's the case you have only to rotate with an angle of 90 degrees because your triangle is special. But if you want to apply a rotation with a specific angle around a specific center you have to use a transformation TRT.
You will find more explanation here.
For a cubic Bézier curve defined by control points P0, P1, P2 and P3 with the formula
B(t)=(1−t)^3*P0 + 3(1−t)^2t*P1 + 3(1−t)t^2*P2 + t^3*P3
we can get a point corresponding to any t ∈ [0,1]. However, from what I've gathered, algebraically solving for either one of the coordinates becomes very tedious and costly, at least for a general solution.
Now, suppose we have a two-dimensional curve B(t)=(x,y) with the specific constraint that dx/dt > 0 for all 0 ≤ t ≤ 1, i.e. the curve can progress to the positive x direction, but never "straight up/down" or "backwards", is there an efficient algorithm (/algebraic manipulation trick) to sort of "sample" the y of the curve with respect to a constant interval Δx that can leverage this property?
I'm going to answer what I think you're asking, rather than what you're actually asking, so if this doesn't cover it (and even if it does) you will want to update your post to clarify what you really mean.
Now, suppose we have a two-dimensional curve B(t)=(x,y) with the specific constraint that dx/dt > 0 for all 0 ≤ t ≤ 1, i.e. the curve can progress to the positive x direction, but never "straight up/down" or "backwards", is there an efficient algorithm (/algebraic manipulation trick) to sort of "sample" the y of the curve with respect to a constant interval Δx that can leverage this property?
Bezier curves are affine transform invariant, so any curve that does fit this definition can be rotated to no longer fit that definition. Let's assume you are referring to some canonical form, where you preprocess the curve by applying a rotation/translate to it such that the first point is at (0,0), and the last point is some coordinate (>0,R) (that is, x coordinate greater than 0, and y coordinate "any real number").
Given that, your constraints mean that the first control point (which determines the tangent at the curve at t=0) must lie strictly to the right of (0,0). The y coordinate is irrelevant (it just needs to be a real number), and the x coordinate can be any real number greater than 0 (even something as close to zero as IEEE floating point numbers allow).
Conversely, the end coordinate needs to be similarly approached, so for any end coordinate (ex,ey), the associated control point (which determines the curve tangent at t=1) needs to lie strictly to the left of (ex,ey); that is, the y coordinate can be anything, and the x coordinate must be to less than ex, but again it can be as close as possible without being ex.
Done, we now have a curve that fits your needs, which leaves the sampling at fixed x interval: you have three options.
The mathematically true way to do this is to reparameterise your curve such that y becomes and expression of x and that is ludicrously hard.
You know the tangent at each point, and Cubic Bezier curves that conform to your needs do not oscillat, so you can compute a guess for "the next x" and then use the Newtonian approach to find the true next x value you need. Or,
solve this the programming way: you're going to be drawing this curve anyway, so during the draw routine, build the LUT for the curve points that need to be drawn to the screen: you now have a list of x values with associated y values and you just need to do a simple lookup.
Obviously, unless you need absolute scientific precision, option 3 is going to be by far the best choice.
I have a set of [x, y, time] values and a reference point [x, y]. The values represent 2D movement of an object over time. I would like to approximate the time at which the trajectory of the object was closest the reference point. In this diagram, the blue crosses are the set of points and the red cross is the reference point.
My initial approach would be to derive the linear trajectory of the object (green line below), and then find the point on the line that forms a right angle with the reference point (PT). The distance of that point between its two nearest neighbours along the trajectory line (T2 and T3) would provide an interpolated time value.
Is there a more efficient algorithm, or set of algorithms, for calculating the time value of PT? A linear approximation for trajectory (as opposed to a spline) is acceptable, as is some tolerance in the accuracy of the calculated time. A reference implementation (in pseudo-code/C/Java/whatever) for study would be most welcome. Many thanks.
EDIT: maybe it's easier to re-phrase in terms of GPS. Given a polyline of GPS points and the time of their reading, at what time precisely did the path go closest to this other point?
Let's say I have a contour shape defined by two functions x(p) and y(p), where p is the distance traveled along the perimeter of the shape, normalized between 0 and 1. For example, a unit circle about the origin would be defined as x(p) = sin(2 * pi * p) and y(p) = cos(2 * pi * p).
A simple test to determine if a point is within that circle would be to calculate the point's distance from the origin, and then detect if that distance is less than or equal to 1.
But what if my shape has multiple crossings, and is much more complicated than a circle?
There exists a point in polygon test for a discrete shape defined by a set of points. That algorithm is pretty easy to find, since it's used in a lot of places. But if I don't want to use a discrete definition of my shape, what algorithm can I use to determine the winding number, with the assumption that the shape is defined at compile time?
Generalizing the point in polygon test, you can find all solutions of y(p)=0 such that x(p)>0 and use the parity of their numbers.
In the case of the circle, cos(2πp)=0 for p=(k+1/2)π, and only one value of p in range [0,1) makes sin(2πp)>0.
So far so good if you can solve the y equation analytically. Otherwise you will need a reliable numerical solver, able to spot all roots. An alternative is to flatten the curve (draw it as a polyline, ensuring a maximum deviation tolerance), and apply the polygon algorithm.
For the sake of a second example, let us consider Pascal's limaçon with equation r = 0.5 + cos Θ, and some test point along X.
y = (0.5 + cos Θ) sin Θ = 0
for Θ=0, 2π/3, π, 4π/3. The corresponding abscissas are 1.5, 0, 0.5 and 0.
You can conclude that the interior points on the X axis are between 0.5 and 1.5 (also at 0, in a degenerate way).
If you know a point that is inside (or outside) the shape and the shape is smooth and non-intersecting, then you can connect the known point to any other point and count the number of times it crosses the boundary. An even number of times means the unknown point is similarly inside (or outside). An odd number means the opposite.
This is based on the Jordan Curve Theorem. As I recall, winding number is needed for the proof of the theorem, but the application is quite easy.
How about computing the total curvature of the closed curve (assuming it is everywhere differentiable), then dividing it by 2PI? See Wiki's Total Curvature page here.