Math (geometry) problem. $20 for best solution!

Beja

Expert
Licensed User
Longtime User
That means you modified the code you gave me.. at least the 'log' because log is only in debug mode..
can you share the project that you compiled to apk?
 

JoanRPM

Active Member
Licensed User
Longtime User
Beja.
Here you are the project.

The formula I obtain is based only in two trigonometry formulas:
h^2 = a^2 + b^2 = r^2 + b^2
b = h * sin(ang)
x = h - r
If you solve this, you can obtain x.

Note: When you "Run" the project with the B4a Program, in the "Logs" zone, you can see the results (in the PC, not in the mobile device).
I use this in "Release mode" and I can see all the results loged. You don't need to debug it.

Regards.
 

Attachments

  • Test.zip
    5.5 KB · Views: 320

Beja

Expert
Licensed User
Longtime User
Hi Joan,
Can you share the project that you run on real device?
Thanks in advance.
'"""""""""""""""""""""""
h^2 = a^2 + b^2 = r^2 + b^2
is this a formula?
'"""""""""""""""""""""""
 

JoanRPM

Active Member
Licensed User
Longtime User
Beja.

I shared yet in post #23. It's the "Test.zip".

h^2 = a^2 + b^2 is the formula for a right triangle.
Below I have replaced the cathetus "a" by the radius "r":
h^2 = r^2 + b^2
 
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
I think my initial equation was slightly wrong.
JoanRPM is also correct, but can be further simplified ( sin^2 + cos^2 = 1)

B4X:
Length of red line = ( (1/CosD(angle)) - 1) * r

However this result is only valid from angle = 0 to 45
After that the tables turn and it becomes:
B4X:
Length of red line = ( (1/SinD(angle)) - 1) * r

I believe when the angle is from -45(315) to 45 and 135 to 225 the first one is valid, and other angles the second is valid.
 

klaus

Expert
Licensed User
Longtime User
The equations I posted in post#6 look a bit more 'complicated' but are valid for both sides of the diagram. The given data, in the question, is the position on the x axis which means that the angle must be calculated before calculating the line length.
The equations were developped to be also able to display the red line, therefor the need for the coordinates of the end points of the line.
 
Last edited:

Beja

Expert
Licensed User
Longtime User
Thanks to all...
Guys, honestly I didn't try your latest solutions but will do asap.
Hi Klaus, the example you provided was perfectly what I was looking for.. I am looking for
0 to 90 degrees but the example was 0 to 180. That's why I looked into the other solutions
with the hope they may address 0 to 90 (only). I think modifying your code to stop at 90
could be my way to go. But this is also not necessary as I can pass any angel degree I wish to your
function.

best regards,
Beja
 

Beja

Expert
Licensed User
Longtime User
Hi Klaus,
Thank you very much, yes this makes it easier.
 

Beja

Expert
Licensed User
Longtime User
B4X:
If you replace in the Sub pnlDraw_Touch routine
'If X >= CenterX - Radius AND X <= CenterX + Radius Then
'by
If X >= CenterX - Radius AND X <= CenterX Then
'You have the left side.

Hi Klaus,
Is it possible that we can, as well, make the red line rotates full cycle for 360 degrees? (0 to 359 OR 1 to 360)
Thank you in advance..

p.s.
sorry for brining up a 3-month old post, but I need the solution for my project : )
 
Last edited:

klaus

Expert
Licensed User
Longtime User
What are the input data ?
In the first question it was moving on the X axis independant of the Y position.
It's easy to modify the program, still depending on the X position, and show the lines in the upper part if Y is in the upper part and show the lines in the lower part if Y is in the lower part.
If you want that the angle is caluclated by the X and Y positions it needs a deeper look into it.
 

Beja

Expert
Licensed User
Longtime User
Klaus,
Thank you.. that was a lot of work, God bless you.
The high precession result is very useful.. as if you read my thoughts.

Dankeschön
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…