
I hope you don't mean you're storing these values as varchar/text/string etc.





When performing calculations on real numbers it's usually best to utilize the full precision of the machine or database environment, then do any rounding only at the final step. If that means you have to carry internal data to 6 decimals, so be it. It doesn't cost you anything in performance and will save a lot of grief when users start looking at your results.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"





Hi,
in order to preserve accuracy, you should keep track of the total amount
(104 in your example) and the total quantity (11). The Avg Selling Price
is of secondary importance. You should not perform a division (which
looses accuracy, especially if you apply rounding to the quotient) and
later try to undo it by multiplying again, just keep track of amount and count.
Amount has no precision problem, since it has a fixed resolution (e.g. 1 cent),
and count is an integer.





Excellent read[^]. It might solve a problem of mine if I can implement it a certain way.





I have a large number of articles. I have a large number of possible keywords. Each article has at least one keyword associated with it, but may have many keywords. There is a database containing a list of all articles and a boolean variable set to true for each keyword if that keyword applies.
A user has a list of all keywords and selects those which interest them.
I am trying to find a more elegant way to extract the list of relevant articles than a brute force SQL SELECT.
Any suggestions would be appreciated!





I guess you will not be able to escape from a select statement...maybe you could try to use a stored procedure for that, or try to optimize the select, but not without a select I think
Intelligence is almost useless for those who have nothing else!
Email: caiokf@gmail.com





I think your database design is not ideal.. You should have a table for all the articles and a table for all possible keywords. In a third table you save all keywordarticle associations (using the primary key of the article and keyword).





There is ABC triangle randomly rotated on XY plane. A,B coords are known, ACB angle is 90'. AC length is known. How to find C coords????
chesnokov





Someone already showed you the way to go.
[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
 Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
 Iain Clarke
[My articles]





If the coordinates of A are (xa,ya) and the coordinates of B are (xb,yb) then the length AB is sqr((xaxb)^2 + (yayb)^2)
The length CB is sqr(AB^2  AC^2) (Length AC is known)
Thus (xcxb)^2 + (ycyb)^2 = CD^2
and (xcxa)^2 + (ycya)^2 = AC^2
As xa, ya and xb,yb and AC are known just expand the two equations, subtract one from the other and the answer should drop out.
Haven't tried it, but the maths is OK!





but (xcxb)^2 + (ycyb)^2 = BC^2
It needs to solve 2nd order equations Ж8О I hed the same before but if there is any easier method?
chesnokov





No, if you reeduce the equations you are left with a simple quadratic.





I think you need to provide more constraints as each side of the hypotenuse segment will result in 2 unique solutions.
A clue to get you going, the distance from the mid of the segment AB to C is equal to the half of AB





Hi arash. Your the expert in geometry, I've seen some of your projects.
There are no more constraints. That ones should be sufficient.
Would you help? to solve the problem?
Is it always half AB if ACB is 90'?
chesnokov





There are two ways of solving this problem, one is to do it algebraically by solving a set quartics based around the circumcircle, the other is simple geometric constructions.
I'll explain the 2nd one as its easier to understand and much easier to program a solution for.
1. Extend perpendiculars to the segment AB, 2 segments one each centered at A and B.
2. The end points for these 2 segments will be called A_0,A_1 and B_0,B_1
3. Extend diagonals from A_0 to B_1 and B_0 to A_1
4. The mid points between A and A_0 will be A_2, similar for the other side B_2
5. Extend diagonals from A_2 to B_0 and from B_2 to A_0
6. The intersection point between the segments A_2B_0 and A_0B_1 will be x_0, similar for the other two diagonals
7. Extend perpendiculars from x_0 and x_1 upon A_0B_0, the points of intersection will be p_0 and p_1
8. Extend segments from A to p_0 and B to p_1, called s_0 and s_1
9. The intersection point between s_0 and A_0B_1 will be C_0
10. The intersection point between s_1 and B_0A_1 will be C_1
11. Symmetric solution can be found by mirroring C_0 and C_1 about AB
A diagram of the solution can be found here:
http://www.partow.net/images/90degreetriangle.png[^]
Various routines in Wykobi can be used in conjunction with each other to solve this construction.
(perpendicular,mirror,project,closest_point_on_segment_from_point etc...)
have fun





That sounds like a whole bunch of work. A simpler solution is to find the midpoint of AB as D, and construct a circle of radius AD centered at D. Since it is given that angle ACB is 90 degrees, point C must also lie on this circle. Since it is given that the distance AC is known, construct a circle at A with a radius AC. Solve the two equations for the two circles for their intersection points. You are correct that there are two possible solutions, one solution on each side of AB.
Dave Augustine





Chesnokov Yuriy wrote: There is ABC triangle randomly rotated on XY plane. A,B coords are known, ACB angle is 90'. AC length is known. How to find C coords????
Start with simpler problem, A at origin, B at (0,c) (i.e. AB = c) and we know AC = b and BC = a. (In your problem you can easily find BC using pythagoras).
The two intersecting circles can be solved almost trivially giving the coords of C (choosing y>0 option) as
x = (b^2 + c^2  a^2)/(2a) y = sqrt(b^2  x^2)
now rotate coords until AB has correct slope (cos = (xb  xa)/c, sin = (yb  ya)/c) and translate A into position.
So the general solution is:
xc = xa + (b * (xbxa)  a*(ybya))*b/c^2
yc = ya + (b * (ybya) + a*(xbxa))*b/c^2
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."





I don't know why this thread has attracted the anonymous univoter. As far as I can see this is the simplest solution so far  can the univoter improve on it?
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."





I'm not sure what you're on about, but the simplest solution to the problem is to assume a square,
from that you get:
c_1,2 = mid(AB) +/ (perp(AB) * AB/ 2)
code:
template<typename T>
void generate_right_triangle(const wykobi::point2d<T>& a, const wykobi::point2d<T>& b,
wykobi::point2d<T>& c1, wykobi::point2d<T>& c2)
{
T distance = wykobi::distance(a,b);
wykobi::point2d<T> mid = wykobi::segment_mid_point(a,b);
wykobi::vector2d<T> v = wykobi::normalize(wykobi::perpendicular(a  b)) * (distance / T(2.0));
c1 = mid + v;
c2 = mid  v;
}
I went for the construction route as most times the nontrivial solutions are more interesting.





Arash Partow wrote: I'm not sure what you're on about, but the simplest solution to the problem is to assume a square,
from that you get:
c_1,2 = mid(AB) +/ (perp(AB) * AB/ 2)
code:
template<typename t="">void generate_right_triangle(const wykobi::point2d<t>& a, const wykobi::point2d<t>& b, wykobi::point2d<t>& c1, wykobi::point2d<t>& c2){ T distance = wykobi::distance(a,b); wykobi::point2d<t> mid = wykobi::segment_mid_point(a,b); wykobi::vector2d<t> v = wykobi::normalize(wykobi::perpendicular(a  b)) * (distance / T(2.0)); c1 = mid + v; c2 = mid  v;}
But what if AC != BC? My simple solution solves this case and does not need wykobi.
All I did was solve for the triangle with A at (0,0) and with AB along the xaxis. The equations solve easily for C, then all you ahve to do is a rotation (using the vector AB) then translate to place A in the correct position. The general problem is done with 4 lines of code and no wykobi:
Input: (xa, ya), (xb, yb) and length of BC = a, to find (xc,yc) st angle(acb) = 90
c = sqrt((xbxa)^2+(ybya)^2)
b = sqrt(c^2a^2)
xc = xa + (b * (xbxa)  a*(ybya))*b/c^2
yc = ya + (b * (ybya) + a*(xbxa))*b/c^2
for the other solution change the sign of 'a' in the last two equations
BTW  It's a pity people 1vote solutions they don't understand.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."





I doubt he was the univoter here.
Unfortunately Mr.Univoter appears quite often in replies to Mr. Chesnokov Yuriy's posts.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
 Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
 Iain Clarke
[My articles]





1. It wasn't me, I don't vote on forum articles
2. The question didn't place any requirements on edge lengths, and if it did my original solution would provide all 4 nontrivial solutions.
3. Can you provide some code to your solution, it would be interesting to see.
4. You provided a solution, others read it and decided to give a rating, no need to get your knickers in a knot.





I didn't look carefully over the other answers but glancing at them, I didn't see anybody mention the obvious: C is on the circle whose diameter is AB. So it amounts to finding the intersection of two circles  one centered at the midpoint of AB with a radius of AB/2, the other with a center at A with a radius of AC. Pretty simple algebra. There will be two answers (one on each side of AB) unless AC = 0 or AC = AB in which case the unique answer is B or A respectively (in which case the "angle" ACB is really not well defined so my claim would be that this case wouldn't fit the requirements of the original question where it was claimed that this angle was unambiguously a right angle  so I would claim there are always two answers).





darrellp wrote: didn't see anybody mention the obvious: C is on the circle whose diameter is AB. So it amounts to finding the intersection of two circles  one centered at the midpoint of AB with a radius of AB/2, the other with a center at A with a radius of AC
This was cross posted, and there was a link on the other page that explained it, and Member 4194593 also explained this.
darrellp wrote: Pretty simple algebra.
Try it  you end up with a quartic for the general case.
If, however, you rotate the triangle so that AB lies on the xaxis, and move A to the origin, the algebra becomes much simpler, you end up with a quadratic that is easily solved. All you have to do then is rotate the result and move it back into position and you have the general solution as I explained. There may be other ways to solve it, but this is the simplest I have found. My solution is correct, as are others (except for those claiming 4 solutions), for some reason the univoters didn't like it.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."





I don't understand the crossposting stuff  I just did a response to the original query. If I screwed up, I apologize but I'm not sure what I need to do differently. If you would enlighten me, that would be great!
I'm glad to hear I just didn't look carefully enough. I'll take your word on complexity. I just saw two second degree polynomials and two solutions and assumed it all boiled down to a simple quadratic. That'll teach me to assume in the future!



