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

Beja

Expert
Licensed User
Longtime User
Hi,
Here is a math problem that I need to solve.. Please see the attachment.
I have $25 (about 15 pounds sterling) for best answer with b4a demo.
In the attached image, I need to know how to calculate the
lengths of the RED distances (lines) as the pointer moves around Axis X
Please put your solution function in b4a example.
circle.png
 

sorex

Expert
Licensed User
Longtime User
are you sure you only need the red lenght?

not the blue or blue+red ?
 

KitCarlson

Active Member
Licensed User
Longtime User
Are the blue lines radi of a circle? If so the math is trivial, it not it the solution is more complex.
 

LucaMs

Expert
Licensed User
Longtime User
X must be between 0 and (center or diameter).

Each time, the length is the hypotenuse of a right triangle

then:

Sqrt (Power(X,2), Power(Y,2))

P.S. Y is the point on a side of the square!

I know, the answer is not complete, but since I do not want the prize, I indicate only the track, not the complete code :D


forget it. I read it wrong. x is fixed? In addition, you want the red lines.

then it becomes a more interesting challenge, with sines and cosines
 
Last edited:

sorex

Expert
Licensed User
Longtime User
maybe he has $25 but only want to spend $20 of it? ;)

he also didn't tell which variable he has, does he have the box coords or the circle ones?
 

sorex

Expert
Licensed User
Longtime User
for straight lines yes, that rule won't work with none 0/90 degrees angles tho
 

klaus

Expert
Licensed User
Longtime User
Is this what you are looking for ?

The routine to calculate the red length:
B4X:
'dx is the distance of x from the center, positive to the right
Sub CalcLength(dx As Double) As Double
    Dim alpha As Double

    x2 = dx
    alpha = ACos(Abs(dx / Radius))
    y2 = Radius * Sin(alpha)
    If alpha > cPI / 4 Then
        y1 = Radius
        x1 = Radius / Tan(alpha) * dx / Abs(dx)
    Else
        y1 = Radius * Tan(alpha)
        x1 = Radius * dx / Abs(dx)
    End If
    Return Sqrt((x2 -x1) * (x2 -x1) + (y2 -y1) * (y2 -y1))
End Sub
 

Attachments

  • Geometry.zip
    6.3 KB · Views: 273
  • Geometry.png
    Geometry.png
    9.7 KB · Views: 310

Beja

Expert
Licensed User
Longtime User
Thanks to all who responded this question..
And Klaus wins the prize!
desolatesoul solution looks compact. I didn't test it though.. but there is no demo container.
@ lukaMs: Thanks to you and sorex for the sarcastic comments, realy cool!
If someone put a statement or promise, on the title, then later he put another
statement or promise, then it is the last statement that's valid. I am sure you know but just a reminder.
but your comment was cool and I give it a big LIKE.
 

LucaMs

Expert
Licensed User
Longtime User
Thanks to all who responded this question..
And Klaus wins the prize!
desolatesoul solution looks compact. I didn't test it though.. but there is no demo container.
@ lukaMs: Thanks to you and sorex for the sarcastic comments, realy cool!
If someone put a statement or promise, on the title, then later he put another
statement or promise, then it is the last statement that's valid. I am sure you know but just a reminder.
but your comment was cool and I give it a big LIKE.


Sorry, Beja, i like to joke :)
 

Beja

Expert
Licensed User
Longtime User
Hi thedesolatesoul,
Trying to implement your code, I got the error msg saying text format not correct
Any information appreciated.. thanks in advance

B4X:
rad = 100
ang = 45
leng = rad * (Sqrt( Sin(ang)^2 + 1) - 1)
Log leng

Error description: Input string was not in a correct format.
Occurred on line: 36
leng = rad . (Sqrt( Sin(ang)^2 + 1) - 1)
 

Beja

Expert
Licensed User
Longtime User
thedesolatesoul, perfect!
Well done and take my word, you don't need to try it!.
After NJDude adjustment now working and I test it with all values for ang.
B4X:
rad = 100
For ang = 1 To 90
leng = rad * (Sqrt(Power(SinD(ang),2) + 1) - 1)
Log(leng)
Next

Thanks to both of you guys.
 

JoanRPM

Active Member
Licensed User
Longtime User
Sorry Beja, but this code dosen't work.
In your code if "ang" is 45º, then "leng" must be 41.42, not 22.47 as your formula says.

Try this one:
B4X:
Dim r, x As Double

r = 100
For ang = 0 To 45
    x = Sqrt(Power((r),2)/(1-Power(SinD(ang),2))) - r
    Log(ang & "= " & x)
Next

It's only valit from 0 to 45 degres. You must add code to solve this!

Regards.
 

Beja

Expert
Licensed User
Longtime User
Hi Joan,
Thanks..
will check this and get back to you.

BTW: did you test it in real device or the emulator?
 
Top