Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

p(t) = (1-t)*p1 + t*p2 , for t ? [0,1], and two 2D p1 and p2 of the form pi=[xi,

ID: 3530856 • Letter: P

Question

p(t) = (1-t)*p1 + t*p2 , for t ? [0,1], and two 2D p1 and p2 of the form pi=[xi, yi] Using this equation, write a function to discretize a line between points p1 and p2, based on a given step size ?t for t and return the computed points. Assume that points holds all computed value pairs in an nx2 matrix form. function points = discretizeLine(p1, p2, stepsize) Note: Make sure that your function properly handles arbitrary step sizes and discretizes the line in some form from beginning to end, using known or computed information and some common sense. Examples: >> discretizeLine([0 0], [1 0], 0.01); >> discretizeLine([0 0], [1 0], 0.6); >> discretizeLine([0 0], [1 0], 2.0);

Explanation / Answer

function [ out ] = Discretize( p1,p2,t )

%DISXRETIZE Summary of this function goes here

% Detailed explanation goes here

theta=atan2(p2(1,2)-p1(1,2),p2(1,1)-p1(1,1));

ii=t*cos(theta);

jj=t*sin(theta);

i=0;


while(1)

out(i+1,1)=p1(1,1)+ii*i ;

out(i+1,2)=p1(1,2)+jj*i;

i=i+1;

if((abs(p1(1,1)+ii*i-p2(1,1))<abs(ii))||(abs(p1(1,2)+jj*i-p2(1,2))<abs(jj)))

break;

end

end

end