Re: unit axis intercepts

new topic     » goto parent     » topic index » view thread      » older message » newer message

I also asked it towrite the code in Euphoria

To determine where a Bezier curve intersects the unit axis and whether it straddles a whole pixel, you can follow these steps in Euphoria:

-- Function to find the intersection points with unit axis 
function findIntersectionPoints(x1, y1, x2, y2) 
    -- Determine whether the curve is flat or steep 
    flat = abs(y2 - y1) < abs(x2 - x1) 
     
    if flat then 
        -- Swap x and y coordinates for a flat curve 
        x1, y1 = y1, x1 
        x2, y2 = y2, x2 
    end 
     
    -- Determine whether the curve is going up or down 
    up = y1 > y2 
     
    -- Calculate the intersection point on the unit y axis 
    if up then 
        hituy = floor(y2) 
    else 
        hituy = ceil(y2) 
    end 
     
    -- Calculate the intersection point on the unit x axis 
    hitux = ((hituy - y1) / (y2 - y1)) * (x2 - x1) + x1 
     
    if flat then 
        -- Swap x and y coordinates back if it's a flat curve 
        hitux, hituy = hituy, hitux 
    end 
     
    -- Check if the intersection point straddles a whole pixel 
    straddles_x = ceil(x1) != ceil(x2) 
    straddles_y = ceil(y1) != ceil(y2) 
     
    return hitux, hituy, straddles_x, straddles_y 
end 
 
-- Example usage 
x1 = 0.5 
y1 = 0.5 
x2 = 1.5 
y2 = 1.9 
 
hitux, hituy, straddles_x, straddles_y = findIntersectionPoints(x1, y1, x2, y2) 
 
if straddles_x then 
    ? "X-axis intersection at ", hitux 
else 
    ? "No X-axis intersection" 
end 
 
if straddles_y then 
    ? "Y-axis intersection at ", hituy 
else 
    ? "No Y-axis intersection" 
end 

This code defines a `findIntersectionPoints` function that calculates where the Bezier curve intersects the unit axis (both X and Y) and whether it straddles a whole pixel. The function accounts for whether the curve is flat or steep and whether it's going up or down. It also provides example usage and prints the results.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu