Finding the apex of a bezier curve - geometry

I'm working in flex, although I reckon this is a language independent problem. I'm trying to draw a curve using 3 points, using curveTo (a quadratic bezier function, I don't believe Flex has any other, if it does, please correct me!) Points 1 and 3 are "nodes", with point 2 being a drag handle.
What I want is not for the line to curve towards point 2 but in fact pass through it. I've managed to get this working by fluking it - by doubling the (distance between the midpoint of a line between Points 1 and 3) and Point 2.
This doesn't put it on the Apex of the line though, just somewhere close to it.
Anyone any ideas?
Andrew

the quadric bezier curve is calculate using the formula
B(t) = (1-t)(1-t)*P0 + 2(1-t)t*P1 + t*t*P2
where P0,P1 and P2 are the 3 points you specify. The curve starts in P0 and ends in P2
t ranges from 0 to 1
the apex should be reached at t = 0.5
so try to insert P0, P2 and t = 0.5 into the formula set it equal to the point where
you want the apex to be and extract P1 from the formula

Us this formula: B'(t) = 3 (1 - t) 2 (P1 - P0) + 6 (1 - t) t (P2 - P1) + 3 t2 (P3 - P2)
You can use the derivative to find maximums and minimums.

A Bezier spline will not pass through its control points, but a Catmull Rom spline will.
B(t) = ((2*P1)+(-P0+P2)*t + (2*P0-5*P1+4*P2-P3)*t*t + (-P0+3*P1-3*P2+P3)*t*t*t )) / 2
Although this is a cubic rather than quadratic spline. You could try making P1=P2

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)

How to calculate the total number of circle coordinates?

If having a centre(xc,yc) and radius(r), how can i calculate total number of coordinates(x,y) in the circle?
I suspect that you are talking about integer points in the circle. Otherwise question is senseless.
In this case you can apply Gauss formula
N = 1 + 4 * r + 4 * sum[i=1..r]{floor(sqrt(r^2-i^2))}
Note that center has integer coordinates too.

Chord height from circle edge in 3 tangent circles

I don't know if this question makes sense, but is there a formulaic way to calculate the height of a chord from a circle's edge in one of the circles from 3 tangent circles?
I have included a diagram to provide detail. Circles C1, C2 and C3 are connected at tangents and have equal radii (in this case 1 mm, but that is only for depiction). Triangle ABC is formed by connecting the centers of these circles. Line LM meets sides AB and AC and is tangential to Circle C1. Line PQ cuts through Circle C1 and triangle ABC and is tangential to both circles C2 and C3.
Diagram for question
What is the formula for the distance (x) between lines LM and PQ?
Given that the radii are equal (say, r), the total height of these 3 circles (line RS shown in diagram, which is my objective to calculate) is 4 times the radius minus the distance (x) between lines LM and PQ. In other words,
|RS| = {(4*r) - x}
variable x needs to be converted into a formula based exclusively on radius r so as to solve this equation.
It has been a while since I revisited my high school geometry lessons, so I hope this can be solved.
Distance A-LM is equal to r (circle center - tangent)
Distance BC-PQ is equal to r
If we add these distances and subtract distance PQ-LM (x), we'll get height of equilateral triangle ABC (with edge 2*r)
r + r - x = height of ABC = 2 * r * sqrt(3)/ 2
x = r * (2 - sqrt(3))

Square divided by a ray. What is the area of a part?

I have a square, for simplicity assume bottom left corner is on origin and width of the square is 1.
A ray divides the square into two parts. I have the coordinates of intersection points. I want to obtain the area that lies right of the vector from p1 to p2:
Right now I have 16 if statements checking every combination of 2 points and calculating the area accordingly. It looks awful. Is there a more clever way of doing this?
Call the points A and B instead of p1 and p2. I'll assume x increases to the right and y increases upward, as per convention.
The point A must have a coordinate (x or y) that is 0 or 1. Rotate the square (really just the two points) to make it x=0.
The point B might be at x=-1, in which case the area is 1-(Ay+By)/2.
Or B might be at y=0, area = 1+(AyBx)/2
Or B might be at y=1, area = (Ay-1)Bx/2
This solution assumes that p1 and p2 form a right-triangle as depicted in the shaded area:
Area to the right of the vector = (w * w) - (0.5 * p1 * p2)
where w is the width of the square, and 0 <= p1 <= w, and 0 <= p2 <= w.
For example if w = 1, p1 = 0.5, and p2 = 0.75
then Area = (1 * 1) - (0.5 * 0.5 * 0.75) = 0.8125

Position from the latitude and longitude of nearby places

How can I calculate the latitude-longitude of a place, when the latitude-longitude information of its 3 nearby places, and the distances to the place are given?
E.g, A,B and C are three places with latitude-longitude (x1,y1), (x2,y2) and (x3,y3). Let D be at distance k1, k2 and k3-km from A, B and C respectively. How can one determine the latitude-longitude of D.
In case, all these points, A,B,C and D are on a plane, then this can be calculated, by determining the point of intersection of the three circles, from A, B and C with radius k1, k2 and k3, respectively. However, how to determine the position, when the points are on a sphere and not on a circle?
Starting with a plane, here is an alternative method to your suggested 3 circles:
Since you know the coordinates of A,B and C, you can calculate the length of AB,AC and BC.
Lets mark by X the point point we want to find.
we know that AX=k1, BX=k2 and CX=k3
Now draw the 3 triangles: ABX, ACX, EDX. We know the length of all their edges, therefore we can calculate the angles.
Knowing all coordinates, lengths and angles we can calculate the coordinates of X.
For a sphere- almost the same idea can be used. However:
Coordinates should be in Lat/Lon radians
Distances should be calculated using great circle distance formula. See Aviation Formulary.
Total angles in a triangle is not 180 - It is between 180 and 540.
Knowing the edges lenghts, angles can be calculated using the spherical law of cosines
Now, coordinates of X can be calculated.
It takes some time to get used to working with spherical trigonometry, however this is the right tool for such problems.
I'll assume k1, k2, k3 are distances on the sphere.
You may be able to solve this most precisely by using a special case of the Vincenty formula. With your three sets of values for x, y, and k, you can set up a system of equations to solve for the latitude and longitude of the fourth point. Solving this system would probably be extremely tricky due to its complexity, but there may be computational tools that could perform such a solve.

Resources