Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Misleadingly Simple Math Problem

Author
Message
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 18th Nov 2010 21:37 Edited at: 18th Nov 2010 21:50
@Visigoth - lol. Yeah. I do have a good handle on trig. Few examples: Orbit Object, ATanFull to get X, Y, Z angles for Hands Point at Point example (Gun pointing at 3d position), and a few others.

I stated that:
Quote: "This function is based on a function lib I found for matrixes."
I found this function and wanted to learn how it works and re-write it using matrixes. I didn't completely understand it though.

Quote: "angC# = acos((a#^2 + b#^2 - c#^2) / (2*a#*b#))
angA# = asin((a# * sin(angC#)) / c#)
angB# = 180.00 - (angA# + angC#)"


Wouldn't ATanFull be easier?


Sorry. Still haven't looked at it yet. Working on my main computer. lolz

Mind explaining how this works:


Also, Does it output the point: (X, Y) (Or at least have global vars X and Y?

Thanks,

DigitalFury
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 18th Nov 2010 21:42 Edited at: 18th Nov 2010 21:42
@Green Gandalf - I Forgot this rule:
Quote: "(a - b)^2 = a^2 - 2*a*b + b^2"
could be used to expand #2 like this:
Quote: "(x1 - x)^2 = x1^2 - 2*x1*x + x^2"


This just makes it and even longer linear equation. Fun! lol
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Nov 2010 23:12
Quote: "Fun!"


Indeed.
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 19th Nov 2010 03:18
@DigitalFury
yeah, I guess atanfull() would be easier, but atanfull() isn't a trig function by itself, its a DBPro function, so, wouldn't work with my source info. Good idea, this makes it EVEN easier.

second function determines the coordinates. Vars for sides and angles were declared as global. Its right at top of full code.

its just a quick example, just to show the method. Get the angles, then plot the coordinates.

all I did was follow the info from this source:
http://www.teacherschoice.com.au/Maths_Library/Trigonometry/solve_trig_SSS.htm

Honestly, I think you know exactly what you are doing.
Good day.
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 19th Nov 2010 03:39
@Visigoth -

Quote: "all I did was follow the info from this source:
http://www.teacherschoice.com.au/Maths_Library/Trigonometry/solve_trig_SSS.htm"


I don't know how this problem solves for point (X, Y).

Quote: "Honestly, I think you know exactly what you are doing."


^^ Sometimes.
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 19th Nov 2010 03:59
@DigitalFury
because in your original post, there are no known angles.
First solve the triangle, to get the angles. That is first function.
Once you know the angles, you can plot the coords using sin() and cos() as a ratio of each length.

I don't know how to explain it any simpler, really. I thought the sample code would illustrate it.

See ya.
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 19th Nov 2010 04:09
@Visigoth - I should be able to figure it out now. I couldn't figure it out just based on the website you gave me. Thanks.

DigitalFury
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 25th Nov 2010 21:02 Edited at: 25th Nov 2010 21:02
I am going to put a pause on this problem until next year. I am working on a small video game demo.

P.S. Sorry for the double post.

DigitalFury
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 1st Dec 2010 00:07 Edited at: 1st Dec 2010 00:09
@Visigoth - Finally got around to looking at your example. My main computer was down until now. Your example is awesome. That should be what I am looking for.

@Green Gandalf -
I am busy working on my current project. As soon as I get to the part of the project where I need this function I will try working on the problem again. Thanks for your help so far!

Check out my current project!

DigitalFury
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 1st Dec 2010 03:44 Edited at: 1st Dec 2010 03:50
@DigitalFury
I tried to tell ya!
just kidding. Hope it works out for you. I'm still looking for all the triangle solving code I wrote, but, sadly, I think it got wiped on an old harddrive. Come to think of it, I might have put them on the old code snippets board...anyway, one of these days I'll write them over. They're just translated from the math source link I posted earlier.

edit:
I noticed on your projects "other inputs" is next in line. Check out Todd Riggin's XBOX 360 dll....works great. I've tested it with 4 controllers, mix of wireless and even a guitar. Works.

http://forum.thegamecreators.com/?m=forum_view&t=155264&b=8
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 1st Dec 2010 04:10
@Visigoth - Nice. The controller plugin looks a lot better then another one I am using. Input is a big feature in my game. Thanks for the link! Check out all my code snippets. Might be something of use.

DigitalFury
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Dec 2010 12:22
Quote: "As soon as I get to the part of the project where I need this function I will try working on the problem again. Thanks for your help so far!"


Don't bother with my solution if you're happy with Visigoth's method - unless you just want to understand how mine works.
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 3rd Dec 2010 23:53 Edited at: 3rd Dec 2010 23:53
@Visigoth - I spent a lot of time looking though your source following all the variables.

I have angles Angle1#, Angle2#, Angle3# corresponding to points 1, 2, 3. I have Dist1#, Dist2#, Dist3# corresponding to a, b, c.

The Type:


The function is:


To make things easier for me could you use your get_coordinates function and rewrite it using my function?

Quote: "eaA#,eaB#,eaC#,esa#,esb#,esc#"

I had a lot of problems following you with these variables.

Thanks,

DigitalFury
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 6th Dec 2010 02:26 Edited at: 6th Dec 2010 02:30
@DF
Only if Dist1#, Dist2#, and Dist3# include the lengths of the sides d,e,f in your first drawing.

Because, you said:
Quote: "The Known:
1, 2, 3 = The Points (X1, Y1), (X2, Y2), (X3, Y3)
a, b, c, d, e, f = Lengths of sides"


I could write it like this:

DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 6th Dec 2010 02:37 Edited at: 6th Dec 2010 03:06
@Visigoth - Yep. I forgot that.

This is what I got:


The internal distances are:


I know these internal distances from some other algorithms.

Quote: "get_coordinates(aA#,aB#,aC#,sa#,sb#,sc#,eaA#,eaB#,eaC#,esa#,esb#,esc#)"

This function is what I confusing me a bit.

This is what I have so far:


I revised this:

I have angles Angle1#, Angle2#, Angle3# corresponding to points 1, 2, 3. I have A#, B#, C#, E#, F# corresponding to a, b, c, d, e, f.

The Type:


The function is:


You stated: xA,yA is the coords. I think that is (X, Y). The point I am trying to find.

I am just a bit lost is all with your variables and forgot about those internal distances.

Thanks,

DigitalFury
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 6th Dec 2010 03:33
I was going to write a big long explanation, but I forgot I put a diagram in the code:

DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 6th Dec 2010 03:52
@Visigoth - Already saw that diagram. I just didn't understand what this was:
. I just figured out it was the external and the
are the internals.

What I didn't understand was this part:



I don't know where some variables are coming from. I don't really understand how it works.

Sorry I am still a bit confused.

Thanks for your help!

DigitalFury
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 6th Dec 2010 04:02 Edited at: 6th Dec 2010 04:11
@DF
ok, there are only 2 functions to do this. All the rest are just there to draw the results to the screen.
I'll try to explain the method.

You have to look back at your drawing in your first post. There are 4 triangles. One big one, and three littler ones inside it.
The function solves for one of the littler ones, and, the big one.

First, solving the triangle.
We need to solve it to get the angles.
We need the angles to figure the coordinates, later.
We solve the triangle using the SSS theorum, translated from the math page.
http://www.teacherschoice.com.au/Maths_Library/Trigonometry/solve_trig_SSS.htm
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 6th Dec 2010 04:09 Edited at: 6th Dec 2010 04:15
just input three valid side lengths of the internal triangle. Those would be params a#,b#,c#, with c# being the longest one. It will be the same number as ec#. (look at your drawing).

anything with an e in front of it represents the larger, external triangle. I had to do this, because if you change the length of some internal lines, it will "push" the external coordinates. If those external coordinates were fixed, and the internal lines were too long, then the internal "random point" would be outside the triangle.
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 6th Dec 2010 04:15
If your internal side lengths are correct, then the coordinate will be correct for the other two triangles. Like I said, we only need to solve for one.
That is the other function, to determine the coordinate.


DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 6th Dec 2010 04:15
@Visigoth - Thanks Again. I'll give this another shot tomorrow.

Did ya check out all the code snippets yet. I updated the input code snippet to include multi-threading cuz I think you said you needed input functions.

DigitalFury
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 6th Dec 2010 04:20
Oh, do I. I'll rewrite the solve triangle function and the coordinate function to be more generic. I know its a little confusing. But you know how it is sometimes, you just get going, and it makes sense at the time.
Thanks man.
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 6th Dec 2010 04:39
@Visigoth - What makes complete sense to one programmer could be complete gibberish to another. I changed my code habits years ago so I write everything so it is as easy as possible to understand. My code use to be completely unreadable for anyone reading it...even unreadable for me years later. lolz

Thanks for the re-write. It will help tremendously.

DigitalFury
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 6th Dec 2010 06:12
ok, as simple as I think I can make it:

DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 6th Dec 2010 06:13
@Visigoth - Thanks a lot. I think it is ready for the code snippet forums. Your demo was great!

Login to post a reply

Server time is: 2026-07-21 18:58:36
Your offset time is: 2026-07-21 18:58:36