geometry - Where a vector would intersect the screen if extended towards it's direction (swift) -
i'm trying write function in swift, returns cgpoint extension of vector (which within screen) intersect screen. let's assume screen 800 x 600. it's scheme:
the function should have following parameters:
func calcpoint(start: cgpoint, end: cgpoint) -> cgpoint
- start: cgpoint(x: x1, y: y1) - beginning of vector.
- end: cgpoint(x: x1, y: y1) - end point of vector.
- the return point 1 @ vector intersects screen (cgpoint(x: x3, y: y3) shown @ scheme).
the values vector start , end aways points within screen (the rectangle 0, 0, 800, 600).
edit (for alexander): there formula, in given situation make easy write function, in not obvious way using if ... else ... , triangle vertices ratio?
to compute point e can @ triangles given setting. have triangle abc , dbe. note similar, such can set following relation ab : ac = db : de using intercept theorem (ab etc. stands line segment between , b). in given setting know points e.
using start , end points given setting:
in case start , end have same x or y-coordinate top bottom or left right border same coordinate.
using absolute values should work 4 corners of rectangle. of course have consider e being out of rectangle, again same relation can used ab : ac = d'b : d'e'
Comments
Post a Comment