estimate angle between two lines y = 1000x and y = 999x - trigonometry

How to estimate the angle between line y = 1000 x and y = 999 x?
I use the calculator and get 10^(-6) but how to approximate it by hand. Does it relate to Taylor Expansion?

The slope of the first line is 1000 and that of the second is 999. Simply use the formula
\theta = \arctan\frac{m_1-m_2}{1+m_1m_2},
where m_1 is the slope of 1000 and m_2 is the slope of 999.
You should get an answer of 1.00099×10^{-6} radians.
To use a Taylor-McLaurin series, you should go by https://math.stackexchange.com/questions/348711/maclaurin-series-for-arctanx-by-successive-differentiation, and substitute the value of \frac{m_1-m_2}{1+m_1m_2} for x in each of the successive terms.

Related

How to know the location of a point in a rotated grid with equal sized square-shaped cells

Given a grid inclined at an angle θ (theta) with equal sized square-shaped cells with indices 00, 01, 02, ..., 55 (where first digit being x index and second being y index, for instance 00 means a cell at the intersection of row 0 and column 0), and a point p(x,y), how can we know that in which grid cell does the point lie without checking all the cells?
For instance, in the image below point p lies in the cell with index 23.
I found one answer at Checking if a point is inside a rotated rectangle that explains how to determine if a point lies inside a rotated rectangle, but with this approach I need to check all the grid cells.
Perhaps the simplest way - rotate point by the same angle (with negative sign) and check new coordinates in axis-aligned grid
nx = x * cos(theta) - y * sin(theta)
ny = x * sin(theta) + y * cos(theta)
row = (int) (ny / cellsize)
col = (int) (nx / cellsize)

In DDA, why are lines sampled in unit intervals of x if gradient <= 1

from Wikipedia,
A linear DDA starts by calculating the smaller of dy or dx for a unit increment of the other. A line is then sampled at unit intervals in one coordinate and corresponding integer values nearest the line path are determined for the other coordinate.
Considering a line with a positive slope, if the slope is less than or equal to 1, we sample at unit x intervals (dx=1) [...]
For lines with a slope greater than 1, we reverse the role of x and y i.e. we sample at dy=1 [...]
Similar calculations are carried out to determine pixel positions along a line with a negative slope
How does the slope (positive or negative) affect the algorithm?
why is the gradient being less or equal to 1 important?
If your gradient is negative (in one of the dimensions) and you walk along that direction with unit increments, you have to adapt your loop to count backwards.
If you walk along the wrong dimension (with unit increments), you will end up with gaps on the line. E.g., if you have slope 2 and you walk along the x-direction, only every second row will contain a pixel.

Calculate place of point C to be equal distance away from points A and B

In the picture below I have a triangle. It represents a mechanical arm, where
A = Shoulder (base point of the object)
B = Hand (turret that shoots at the player)
C = Elbow
x = Upper arm (same length as z)
y = Distance between Shoulder and Hand
z = Lower arm (same length as x)
Point B can freely move around point A as long as it doesn't go too far away (pre-determined value). The position of point C should be calculated so that the lines x and z doesn't suffer any changes in length. In other words, point C has to stay a pre-determined distance away from points A and B. How should I calculate this?
First observation (you can't overstretch and you can't touch your shoulder if your under arm is shorter than your upper arm):
| x - z | <= | y | <= | x + z |
Next, it can be calculated with the cosine rule, where you can calculate any angle you want (e.g. angle a = CAB).
From there you can calculate C.

How to return fitting equation in excel

In excel, I am doing a simple linear regression of two vector X and Y. When I plot X vs Y and fit with linear equation and the result y = kx + b can be shown in the figure. I need to use k and b for my further calculation. I am wondering if there is any equation that can direct return the value of k and b in excel.
Many thanks in advance for he help!
Assuming x values are in A2:A10 and y in B2:B10, your slope (k) with:
=LINEST(B2:B10,A2:A10)
and the intercept (b) with:
=INTERCEPT(B2:B10,A2:A10)

Rating the straightness of a line

I have a data set that defines a set of points on a 2-dimensional Cartesian plane. Theoretically, those points should form a line, but that line may be perfectly horizontal, perfectly vertical, and anything in between.
I would like to design an algorithm that rates the 'straightness' of that line.
For example, the following data sets would be perfectly straight:
Y = 2/3x + 4
X | Y
---------
-3 | 2
0 | 4
3 | 6
Y = 4
X | Y
---------
1 | 4
2 | 4
3 | 4
X = -1
X | Y
---------
-1 | 7
-1 | 8
-1 | 9
While this one would not:
X | Y
---------
-3 | 2
0 | 5
3 | 6
I think it would work to minimize the sum of the squares of the distances of each point from to a line (usually called a regression line), then determine the average distance of each point to the line. Thus, a perfectly straight line would have an average distance of 0.
Because the data can represent a line that is vertical, as I understand it, the usual least-squares regression line won't work for this data set. A perpendicular least-squares regression line might work, but I've had little luck finding an implementation of one.
I am working in Excel 2010 VBA, but I should be able to translate any reasonable algorithm.
Thanks,
PaulH
The reason things like RSQ and LinEst won't work for this is because I need a universal measurement that includes vertical lines. As a line's slope approaches infinity (vertical), their RSQ approaches 0 even if the line is perfectly straight or nearly so.
-PaulH
Sounds like you are looking for R2, the coefficient of determinism.
Basically, you take the residual sum of squares, divide by the sum of squares and subtract from 1.
Use a Linear Regression. The "straightness" of the line is the R^2 value.
A value of 0 for the R^2 value implies it is perfectly straight. Increasing values imply increasing error in the regression, and thus the line is less and less "straight"
Could you try to catch the case of the vertical line before moving the least squares regression? If all x-values are the same, then the line is perfectly straight, no need to calculate an r^2 value.
Rough idea:
1. translate all coordinates to absolute values
2. calculate tan of current x/y
3. calculate tan of difference in x/y between current x/y and next x/y
4. difference in tan can give running deviation
Yes, use ordinary least squares method. Just use the Slope and Intercept functions in a worksheet. I expect there is a simple way to call these from the VBA codebehind.
Here's the VBA info. for R-Squared: http://www.pcreview.co.uk/forums/thread-1009945.php

Resources