Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ray intersection js

function lerp(A, B, t) {
    return A + (B - A) * t;
}

function getIntersection(A, B, C, D) {
    const tTop = (D.x - C.x) * (A.y - C.y) - (D.y - C.y) * (A.x - C.x);
    const uTop = (C.y - A.y) * (A.x - B.x) - (C.x - A.x) * (A.y - B.y);
    const bottom = (D.y - C.y) * (B.x - A.x) - (D.x - C.x) * (B.y - A.y);

    if (bottom != 0) {
        const t = tTop / bottom;
        const u = uTop / bottom;

        if (t >= 0 && t <= 1 && u >= 0 && u <= 1) {
            return {
                x: lerp(A.x, B.x, t),
                y: lerp(A.y, B.y, t),
                offset: t
            }
        }
    }

    return null;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native bootsplash generate splash 
Javascript :: reactjs moment to string 
Javascript :: JavaScript date format 2 
Javascript :: nextjs check path 404 
Javascript :: javascript to jquery code converter online 
Javascript :: mobile angular service 
Javascript :: white space below image next image 
Javascript :: cargar un select con javascript dependiendo de otro select 
Javascript :: Assigning All NodeLists A New Function 
Javascript :: × error: element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. you likely forgot to export your component from the file it 
Javascript :: ... in javascript 
Javascript :: regex capture group example 
Javascript :: javascript brightness filter 
Javascript :: how to do a function after a set interval js 
Javascript :: node js mongodb update nested object 
Javascript :: react native qr code scanner 
Javascript :: SELECT * FROM USERSs 
Javascript :: what is react easy emoji 
Javascript :: postgres json 
Javascript :: filter properties from object javascript 
Javascript :: javascript set header text 
Javascript :: return statement in javascript 
Javascript :: context menus use 
Javascript :: javascripts events 
Javascript :: js get smallest value of array 
Javascript :: JS longest word 
Javascript :: js upload file size limit 
Javascript :: how do you calculate what percentage a number is of another number 
Javascript :: how to check if input is valid javascript 
Javascript :: javascript javascript javascript javascript javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =