Parabola and the corresponding point on the directrix [closed] - geometry

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Suppose we have the equation of the parabola (y = x^2). See the figure below:
suppose we have a point P on this parabola, where P=(-2,4). We know that the distance between any point on parabola (e.g. P) and the focus is equal to the distance
between the point P and the directrix.
My question is, What the corresponding point (e.g. P') of P on the directrix of the parabola, where the distance between the focus and P = distance between P and P'? What is the equation which takes a point on the parabola and return the corresponding point on the directrix

Since focus and directrix have equal distance from any point on the parabola, they in particular have equal distance from the origin (0,0). You may assume that distance fo be d, so the focus would be at (0,d) and the directrix would be the line y=-d.
For any other point on the parabola, the squared distance to the line is
(y+d)2 =
(x2+d)2 =
x4 + 2dx2 + d2
and the squared distance to the focus is
x2 + (y-d)2 = x2 + (x2-d)2 = x2 + x4 - 2dx2 + d2
These two expressions should be equal, so their difference should be zero:
(x4 + 2dx2 + d2) -
(x2 + x4 - 2dx2 + d2) =
(4d-1)x2
From this you can read d=1/4. So your directrix is y=-1/4 and your focus is (0,1/4).
The point on the directrix which corresponds to a point on the parabola is simply its orthogonal projection. So if you have P=(x,y)=(x,x2) on the parabola, then you get P'=(x,-d)=P(x,-1/4).

Related

Find intersecting points on rectangle edges for line drawn inside it [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
Draw a rectangle ABCD.
Draw a line inside it connecting any two edges GF.
Draw a perpendicular bisector to line GF.
At what points does the perpendicular bisector intersect the edges of the rectangle?
In the following image, line GF is drawn from (0, 2) to (6, 0). I need to know where does the perpendicular bisector intersects the rectangle on AB and CD.
Line inside rectangle
Middle point of GF
M.X = (G.X + F.X) / 2
M.Y = (G.Y + F.Y) / 2
Perpendicular vector to GF
D.X = G.Y - F.Y
D.Y = F.X - G.X
Parametric equation of bisector
X = M.X + t * D.X
Y = M.Y + t * D.Y
Solve these equations for X = XLeft, X = XRight, Y = YTop, Y = YBottom, and you'll get intersection points
For example, at first you solve equation XLeft = M.X + t * D.X to find parameter t for intersection point with the left edge of rectangle.
Then check if Y' = M.Y + t * D.Y is in range (YTop..YBottom) for t found.
If yes, then bisector intersects the left edge in point (XLeft, Y')

Finding Shortest Distance Between Two Parallel Lines, With Arbitrary Point [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I need to write a reliable method to retrieve the answer to the following scenario...
Given a line segment AB and an arbitrary point C, how would I find the closest point to A on a line parallel to AB that passes through point C? (Reliable mentioned above refers to the algorithms ability to find D while allowing the coordinates for A, B, and C to be completely arbitrary and unpredictable. I've ran in to a quite a few solutions that I was not able to adapt to all possible scenarios, sadly...)
In the case of the data displayed in the picture below, how would I reliably find the x,y coordinates of D?
A = <425, 473>
B = <584, 533>
C = <371, 401>
D = <???, ???>
Knowing that AB and CD are parallel, that obviously means the slopes are the same.
I have tried many different formulas to no avail and have been working on this for weeks now. I'm stumped!
It's a minimization problem.
In general, the Euclidean distance between two points (A and B) in N dimensional space is given by
Dist(A,B) = sqrt((A1-B1)^2 + ... + (AN-BN)^2)
If you need to find the minimum distance between a space curve A(t) (a 1-dimensional object embedded in some N dimensional space) and a point B, then you need to solve this equation:
d Dist(A(t),B) / dt = 0 // (this is straightforward calculus: we're at either a minimum or maximum when the rate of change is 0)
and test that set of roots (t1, t2, etc) against the distance function to find which one yields the smallest value of D.
Now to find the equation for the parallel line passing through C in y=mx+b form:
m = (Ay - By)/(Ax-Bx)
b = Cy - mCx
Let's write this in space-curve form as and plug it into our formula from part 1:
Dist(D(t),A) = sqrt((t-Ax)^2 + (m*t+b-Ay)^2)
taking our derivative:
d Dist(D(t),A)/ dt = d sqrt((t-Ax)^2 + (m*t+b-Ay)^2) / dt
= (t + (m^2)*t - Ax + m*b - m*Ay)/sqrt(t^2 + (m^2)t^2 - 2*t*Ax + 2*m*t*b - 2*m*t*Ay + (Ax)^2 + (Ay)^2 + b^2 - 2*b*Ay )
= ((1+m^2)*t - Ax + m*b - m*Ay)/sqrt((1+m^2)*(t^2) + 2*t*(m*b - Ax - m*Ay) + (Ax)^2 + (Ay)^2 + b^2 - 2*b*Ay )
Settings this equal to 0 and solving for t yields:
t = (Ax-m*b+m*Ay)/(1+m^2)
as the only root (you can check this for yourself by substituting back in and verifying that everything cancels as desired).
Plugging this value of t back in to our space curve yields the following:
D=<(Ax-m*b+m*Ay)/(1+m^2),b+m*(Ax-m*b+m*Ay)/(1+m^2)>
You can then plug in your expressions for m and b if you want an explicit solution in terms A,B,C, or if you only want the numerical solution you can just compute it as a three step process:
m = (Ay - By)/(Ax-Bx)
b = Cy - mCx
D=<(Ax-m*b+m*Ay)/(1+m^2),b+m*(Ax-m*b+m*Ay)/(1+m^2)>
This will be valid for all cases with parallel straight lines. One caveat when implementing it as a numerical (rather than analytical) code: if the lines are oriented vertically, calculating m = (Ay-By)/(Ax-Bx) will result in division by 0, which will make your code not work. You can throw in a safety valve as follows:
if( Ax == Bx) {
D = <Cx,Ay>
} else {
// normal calculation here
}
For serious numerical work, you probably want to implement that in terms of tolerances rather than a direct comparison due to roundoff errors and all that fun stuff (i.e., abs(Ax-Bx) < epsilon, rather than Ax==Bx)

Get the position of the point that lies at 25% of a line? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a line with 2 points. I know the distance between the 2 points. I also calculated the angle of the line.
My target is to get a point that lies at 25% ot the line.
I calculate the y of this point with (dist/100)*25.
My only problem is calculating the x of the point. I suspect i have all the variables needed i only can't seem to find how to calculate the x. Does anybody know this?
You have a segment (not line) with endpoints P0 (coordinates x0,y0) and P1(x1,y1). New point P lies at this segment and distance |P0P| = 0.25 * |P0P1|, if their coordinates are:
x = x0 + 0.25 * (x1-x0)
y = y0 + 0.25 * (y1-y0)
It's just simple vector maths, no need for any angles or trig here.
startPos = (0,0)
endPos = (10,10)
fratcion = 0.25
distX = endPos.x - startPos.x
distY = endPos.y - startPos.y
pos.x = startPos.x + fraction*distX
pos.y = startPos.y + fraction*distY

Calculate Bezier AABB

I'd like to calculate the AABB (axis aligned bounding box) for a quadratic or bezier curve.
The only way I know how to do this is evaluating a high number of points on the bezier curve, and then use those points to calculate the AABB.
Is there a better way?
Great resource on Bezier curves, and working example of AABB http://pomax.github.io/bezierinfo/#boundingbox
For quadratic curve if you need it, also calculate this using derivatives.
Always avoid iterative methods when closed form is available.
It should be possible by looking for minimum and maximum thanks to the derivative of the curve in parametric form. have a look at this article: http://nishiohirokazu.blogspot.jp/2009/06/how-to-calculate-bezier-curves-bounding.html
The quadratic bezier curve consists of 2 coordinate functions — x(t) and y(t) where.
These functions may have maximum or minimum (the points where x'(t) = 0 and y'(t) = 0) and these points are the boundary points of the aabb.
So the algorithm is:
Imagine x0, y0, x1, y1, x2, y2 are known and calculate the values t(x0, x1, x2) and t(y0, y1, y2) when x'(t) = 0 and y'(t) = 0 respectively.
Calculate both values and check whether they are >= 0 and <= 1. If they are evaluate the points of the quadratic bezier.
Take the first and the last points.
Now you have 4 points (or maybe less), use them to calculate AABB.
By the way:
t(x0, x1, x2) = (x0 - x1) / (x2 - 2 * x1 + x0)
t(y0, y1, y2) = (y0 - y1) / (y2 - 2 * y1 + y0)
You can find the full code here: https://github.com/keyten/Graphics2D/blob/Delta/Core/Curve.Math.js#L295

How to calculate angle between two direction vectors that form a closed/open shape?

I am trying to figure out the correct trig. eq./function to determine the following:
The Angle-change (in DEGREES) between two DIRECTION VECTORS(already determined), that represent two line-segment.
This is used in the context of SHAPE RECOGTNITION (hand drawn by user on screen).
SO basically,
a) if the user draws a (rough) shape, such as a circle, or oval, or rectangle etc - the lines that makes up that shape are broken down in to say.. 20 points(x-y pairs).
b) I have the DirectionVector for each of these LINE SEGMENTS.
c) So the BEGINNING of a LINE SEGMENT(x0,y0), will the END points of the previous line(so as to form a closed shape like a rectangle, let's say).
SO, my question is , given the context(i.e. determinign the type of a polygon), how does one find the angle-change between two DIRECTION VECTORS(available as two floating point values for x and y) ???
I have seen so many different trig. equations and I'm seeking clarity on this.
Thanks so much in advance folks!
If (x1,y1) is the first direction vector and (x2,y2) is the second one, it holds:
cos( alpha ) = (x1 * x2 + y1 * y2) / ( sqrt(x1*x1 + y1*y1) * sqrt(x2*x2 + y2*y2) )
sqrt means the square root.
Look up http://en.wikipedia.org/wiki/Dot_product
Especially the section "Geometric Representation".
You could try atan2:
float angle = atan2(previousY-currentY, previousX-currentY);
but also, as the previous answers mentioned, the
angle between two verctors = acos(first.dotProduct(second))
I guess you have the vector as three points (x_1, y_1), (x_2, y_2) and (x_3, y_3).
Then you can move the points so that (x_1, y_1) == (0, 0) by
(x_1, y_1) = (x_2, y_2) - (x_1, y_1)
(x_2, y_2) = (x_3, y_3) - (x_1, y_1)
Now you have this situation:
Think of this triangle as two right-angled triangles. The first one has the angle alpha and a part of beta, the second right-angled triangle has the other part of beta.
Then you can apply:
You can calculate alpha like this:
If I understand you correctly, you may just evaluate the dot product between two vectors and take the appropriate arccos to retrieve the angle between these vectors.

Resources