#Generating a Union based off 3 points in space

56 messages · Page 1 of 1 (latest)

round harbor
#
function GenerateTriangle(A:Vector3, B:Vector3, C:Vector3)
    local center = (A + B + C ) /3
    local normal = (B-A):Cross(C-A).Unit
    
    local triOne = script.Triangle:Clone()
    local triTwo = script.Triangle:Clone()
    
    triOne.Parent = workspace
    triTwo.Parent = workspace
        
    --midpoints 
    local x = (A + B)/2
    local y = (B + C)/2
    local z = (C + A)/2
    
    
    --TY CHATGPT FOR THE MATH FOR POINT β
    local v = C - B -- Direction vector of BC
    local w = A - B -- Vector from B to A

    -- Project w onto v
    local t = w:Dot(v) / v:Dot(v)

    -- Find beta
    local beta = B + t * v
    
    triOne.Size = Vector3.new(0, (A-y).Magnitude, (beta-C).Magnitude)
    triOne.CFrame = CFrame.lookAlong(z, (C-beta), (A-beta))
    
    triTwo.Size = Vector3.new(0, (A-y).Magnitude,(beta-B).Magnitude)
    triTwo.CFrame = CFrame.lookAlong(x, B-beta, (A-beta))
end
manic wadi
#

I havent done generative stuff like this before so

#

not sure how helpful ill be

#

but it looks visually like a formula problem

round harbor
#

yea if theres an issue with the math its probably beta

#

i straight up gave up[ trying to calculate it myself and chatGPT seemed to rpovide something that "works"

manic wadi
#

hrrmmm

#

wait

#

let me just ask you my first theory

manic wadi
#

but how did you handle the floats

round harbor
#

they're all numbers

#

unelss vector3:Cross() rounds them

#

it should be maintaingin constant precision

hollow scarab
round harbor
#

yea

hollow scarab
#

ok

manic wadi
#

i know certain roblox formulas

#

auto fuck up

#

and change to decimals

#

so lemme check

round harbor
hollow scarab
#

btw u only need one tri

#

just clone twice

manic wadi
#

^

#

what is the other tri for exactly

hollow scarab
#

never rely on chat gpts

manic wadi
#

what like the left and right side

round harbor
#

idk how you'd use only one triangle

#

they're never the same unless its a symmetrical

hollow scarab
#

unless ur doing right triangles

manic wadi
hollow scarab
#

then theres ur answer

manic wadi
#

but whats the 2nd unique one for

#

actually nvm

hollow scarab
#

ur very smart

manic wadi
#

im silly

#

indeed

#

I assumed what he was doing was having 2 unique wedges

#

not the same

#

:3

hollow scarab
#

interesting

round harbor
#
    local DA_unit = (normal:Cross(C-B) + normal*(normal:Dot(C-B)) ).Unit
    local area = 0.5 * ((B-A):Cross(C-A).Magnitude)
    local h = (2 * area )/  ((B-C).Magnitude)
    local D = A - DA_unit*h --Point D, is point A projeted onto the line BC
#

i renamed point D to point B

manic wadi
#

I'm glad you were able to do it!

round harbor
#

basically it caclualtes the area of the trianlge given the 3 points, then uses the normal 2D formula to caluate the length then offsets from D

manic wadi
#

i like how you changed the coloring too. makes your hard work look even more pretty

round harbor
#

DA Unit is just BC rotated 90 btw

round harbor
round harbor
#

i merge the two triangles, to create the final part using UnionAsync()

#

i mjust surprsied that it doesn't remove the colro and revert it back to grey