Author Topic: How about a 3D-embedded triangle?  (Read 4354 times)

0 Members and 1 Guest are viewing this topic.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
How about a 3D-embedded triangle?
« on: June 20, 2020, 01:16:11 am »
I'll make this pretty simple.

Consider a 3D space that embeds a triangle having vertices:
Code: [Select]
(1,1,0)
(1,0,1)
(0,1,1)

Now, consider these "random" single points:
Code: [Select]
(.66,.66,.66)
(.46,.66,.86)
(.83,.89,.26)
(.55,.55,.55)
(.75,.79,.46)
(.79,.89,.66)

Question: Which two of the points given are not in the plane of the triangle, contained within its sides?

Hints and/or Comments:
The rest of the points do live in the plane of the triangle.
I generated all valid points with the same equation, and then simply invented two nonsense ones.
The triangle given is extremely simple but don't get too comfortable with this one. Your thought needs to work for any triangle oriented in any way in 3D.

Bah, that's enough.

Oh and if your name is MasterGy, I assume you've got this. No need to flex but you are 1000% welcome.
Same with Luke and a few others who can't be bothered with such vector trivialities.

Oh and I'll attach an image of a triangle with a line touching it, and then you can imagine that line could have stopped anywhere.
« Last Edit: June 20, 2020, 01:30:19 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #1 on: June 20, 2020, 03:37:30 am »
Is this not simply rotating axes * so that the triangle lies in, say, the xy plane and then seeing which points lie inside the triangle (as already covered)?  Or is it somehow more complicated than that?
* A standard mathematical 3D manipulation for those with the skill?
« Last Edit: June 20, 2020, 05:33:07 am by Qwerkey »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #2 on: June 20, 2020, 07:32:25 am »
Quote
Is this not simply rotating axes * so that the triangle lies in, say, the xy plane and then seeing which points lie inside the triangle (as already covered)

That's a completely legitimate interpretation of this problem. In "real life", you would center your view of the triangle to see what occurs inside its boundaries... but then you'd need a side view to make sure the line actually touches the triangle. Ideally you can do that in one nice calculation...

There may be other ways using CLEAR, SLEEP, PRINT, LINE, etc., Maybe even _MEM ;-)
« Last Edit: June 20, 2020, 07:35:31 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #3 on: June 21, 2020, 01:13:23 pm »
Ooookay, buzzer has sounded, pencils down, pass in your work and seeya Monday.

Here is the answer. Of the points provided, sum across each row using the calculator of your choice. You will find:

Code: [Select]
sum(<.66,.66,.66>) = 1.98
sum(<.46,.66,.86>) = 1.98
sum(<.83,.89,.26>) = 1.98
sum(<.55,.55,.55>) = 1.65
sum(<.75,.79,.46>) = 2.00
sum(<.79,.89,.66>) = 2.34

Four of these numbers are very close to 2.0, but two of them are way off. Evidently, there is something about the equation

x + y + z = 2

... I'll stop here and divert to the PDF linked below. I'll attach a picture below for the problem setup you should be picturing.

The full solution is at the bottom on this link:

http://barnes.x10host.com/homedata/Vectors%20and%20Trigonometry.pdf

... just look for the same picture. Also - talking to you @bplus - if you scroll upward in that document you'll see most of the math problems we've hit over the last year or so.

You're not done when it works, you're done when it's right.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #4 on: June 21, 2020, 01:28:01 pm »
My first reaction is: a linear addition of values from three orthogonal axes has no meaning at all (it's always square/add/square root), so what on earth is he up to now?  I'll have to study this after class (tomorrow)!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #5 on: June 21, 2020, 01:47:13 pm »
Quote
Also - talking to you @bplus

As a matter of fact, bplus IS working on this problem independently (of vectors of course) but is still trying to check/settle an issue with 2D math concerning the "fix"ing of angles.

It might be an interesting alternative to vectors, it might fail in 3D but does it even work in 2D, should know in about 5 minutes (that's programmer's time not real time ;-))

BTW screw this:
Quote
Ooookay, buzzer has sounded, pencils down, pass in your work and seeya Monday.

It's a cool problem to work on. :)
« Last Edit: June 21, 2020, 01:51:40 pm by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #6 on: June 21, 2020, 02:31:46 pm »
Lol don't take me seriously, I thought people gave up.
You're not done when it works, you're done when it's right.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #7 on: June 21, 2020, 02:57:22 pm »
Qwerkey, you do talk rubbish: x + y+ z = constant is just the equation of a (plane) surface as STxAxTIC was using.
Last year, the American Institute of Mathematical Sciences invited me to give a lecture tour entitled "Qwerkey Talks Nonsense".  They've invited me back this year with the talks entitled "Qwerkey Talks More Nonsense".  And I'm working on next year's  "Qwerkey Talks Even More Nonsense".  Why do they let me anywhere near this site?
« Last Edit: June 21, 2020, 03:05:47 pm by Qwerkey »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #8 on: June 21, 2020, 10:44:22 pm »
Code: QB64: [Select]
  1. _TITLE "STx How about a 3D embedded triangle?"
  2.  
  3. ' I am translating Ashish idea to 3D
  4.  
  5. DEFDBL A-Z
  6. TYPE xyz
  7.     x AS DOUBLE
  8.     y AS DOUBLE
  9.     z AS DOUBLE
  10.  
  11. 'given 3d tri
  12. '(1,1,0)
  13. '(1,0,1)
  14. '(0,1,1)
  15. DIM tri(2) AS xyz
  16. tri(0).x = 1: tri(0).y = 1: tri(0).z = 0
  17. tri(1).x = 1: tri(1).y = 0: tri(1).z = 1
  18. tri(2).x = 0: tri(2).y = 1: tri(2).z = 1
  19.  
  20. 'given test cases   6 points in 3d tri or not? 2 are made up the remaider are in which is which?
  21. '(.66,.66,.66)
  22. '(.46,.66,.86)
  23. '(.83,.89,.26)
  24. '(.55,.55,.55)
  25. '(.75,.79,.46)
  26. '(.79,.89,.66)
  27. DIM test(5) AS xyz
  28. test(0).x = .66: test(0).y = .66: test(0).z = .66 'on/in
  29. test(1).x = .46: test(1).y = .66: test(1).z = .86
  30. test(2).x = .83: test(2).y = .89: test(2).z = .26
  31. test(3).x = .55: test(3).y = .55: test(3).z = .55 '
  32. test(4).x = .75: test(4).y = .79: test(4).z = .46
  33. test(5).x = .79: test(5).y = .89: test(5).z = .66 '
  34.  
  35. triArea = HeroArea(tri(0), tri(1), tri(2))
  36. PRINT "Main Triangle Area "; triArea
  37. FOR i = 0 TO 5
  38.     tArea1 = HeroArea(tri(0), tri(1), test(i))
  39.     'PRINT tArea1,
  40.     tArea2 = HeroArea(tri(1), tri(2), test(i))
  41.     'PRINT tArea2,
  42.     tArea3 = HeroArea(tri(2), tri(0), test(i))
  43.     'PRINT tArea3,
  44.     sum = tArea1 + tArea2 + tArea3
  45.     PRINT "Sum of sub tri"; sum; "  differance to Main"; sum - triArea
  46.     IF sum <= triArea + .001 THEN
  47.         PRINT "Test point"; i; " is on/in the triangle."
  48.     ELSE
  49.         PRINT "Test point"; i; " is NOT on/in the triangle."
  50.     END IF
  51.     PRINT
  52.  
  53. FUNCTION HeroArea (p1 AS xyz, p2 AS xyz, p3 AS xyz)
  54.     a = dist3D(p1, p2)
  55.     b = dist3D(p2, p3)
  56.     c = dist3D(p3, p1)
  57.     s = (a + b + c) / 2
  58.     HeroArea = SQR(s * (s - a) * (s - b) * (s - c))
  59.  
  60. FUNCTION dist3D (p1 AS xyz, p2 AS xyz)
  61.     dist3D = SQR((p1.x - p2.x) ^ 2 + (p1.y - p2.y) ^ 2 + (p1.z - p2.z) ^ 2)
  62.  

This should work with any Triangle in 3D.
« Last Edit: June 21, 2020, 10:47:01 pm by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #9 on: June 21, 2020, 11:02:40 pm »
Nice, seems legit! I banged it around a little and it seems solid. Nice work, very!
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #10 on: June 21, 2020, 11:27:09 pm »
Thanks, I had a whole 'nother angle in mind literally, but then I looked up 3D angles, uh-oh, dot product, LOL.

I was wondering if Ashish would get something up first, it's the same idea applied to 3D.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #11 on: June 22, 2020, 09:41:48 am »
@bplus
I had used the *exact* the same idea you have used for solving this problem. @STxAxTIC know this as I discussed this with him at Discord. However, when I run
my program, it doesn't print any point which are NOT in the triangle.

Oh I see, you have added .001 in your condition. ;)
Nice!
« Last Edit: June 22, 2020, 09:42:59 am by Ashish »
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #12 on: June 22, 2020, 10:50:48 am »
@bplus
I had used the *exact* the same idea you have used for solving this problem. @STxAxTIC know this as I discussed this with him at Discord. However, when I run
my program, it doesn't print any point which are NOT in the triangle.

Oh I see, you have added .001 in your condition. ;)
Nice!

Yes, rounding errors makes everything a little more than it is (when squaring stuff allot to have abs values), but @Ashish you encountered that in your clever 2D solution.

Yesterday I spent afternoon reworking my method for 2D solution from points Interior to an angle thinking it might be applicable to 3D as Ashish sol'n based on Triangle Areas. I had a hell of time with blunders or something, prolonged senior moment? Finally I resorted to OPTION _EXPLICIT and had the whole matter cleared up in 5 minutes literally it seems. Then I looked up calculating 3D angles and get this:
  [ You are not allowed to view this attachment ]  

So dang, back to vector math so what is  A . B ?
https://www.mathsisfun.com/algebra/vectors-dot-product.html
It is ax * bx + ay * by + az * bz, not so bad

OK, so what is |A| ?  well it just SQR( A . A )

IF COS(theta) = that mess on right THEN ARC-COS(the mess on right) = the dang angle between the two arms A and B.

OK, so now I am going to try my Interior Angle approach as I finally got it worked to my satisfaction in 2D.
Just for some practice with what I call doorway problems that open up new vistas or new realm of skills.

I learned SIN and COS in math classes but I didn't really learn it until I wanted to draw a hexagon on the computer, that was a doorway problem and I am thinking Angles in 3D might also be one.

So what new blunders await us today :-))

« Last Edit: June 22, 2020, 12:25:13 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #13 on: June 22, 2020, 06:00:49 pm »
Blunder

OK the Interior of Angles in 3D are cones.

Update: wait... no, the 2 rays of an angle do form a plane or a boring slide that no water-park would ever purchase ;-))
« Last Edit: June 22, 2020, 10:07:01 pm by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: How about a 3D-embedded triangle?
« Reply #14 on: June 24, 2020, 02:10:04 am »
Hi
it is very impressive how coding can be useful in math! I never have imagined this strong connection between math and programming.
I like math but after a while my brain stops to think if still I am on an abstract formula.... so I have little resource to  use for complex math solutions...nevertheless my brain works better and stay longer active if there is a geometric question. I like so much Logical geometry!
when I read this kind of thread, the only thing that I can do is to follow your discussions and your solutions...with admiration.
Programming isn't difficult, only it's  consuming time and coffee