Tran Tran

Submit solution for cody but my code has a built-in function

Tran Tran on 1 Mar 2022
Latest activity Reply by Tran Tran on 2 Mar 2022

Hi everyone
I am a new of this community and I very interested in this forum and Matlab.I am trying to submit a soultion but as tiltle my code has a built-in function so the test systerm dont reconisie it.It run completely ok on my computer.
This is problem
This is my solution
function [boOut] = BoIfPointInPoly(PolyMatrix,p_test)
%Summary of this function goes here
if we draw a line from test point to a central point of a side of The polygon
then we extend that line to the furthest point of the polygon ensure that
line go through all side of Polygon in 1 direction.I call that line is line_test
Next find number of intersert of line test and all sides w polyxpoly
num interset point is odd mean p_test inside
num interset point is even mean p_test outside
this solution go from the concept that if a line go in from a side it has go out
from other side.So if it go in but not go out that mean it start from
% Detailed explanation goes here
%line from p test throuh central of a side to furthest point of polygon
%find vector
V = ((PolyMatrix(1,:) + PolyMatrix(2,:)) /2) - p_test ;
%draw that vector to furtest point
pend = p_test + V * max(PolyMatrix(:));
%with multi of V and biggest element I assume that line will go all out the
%polygon which ensure out logic will right
line_test = [p_test ; pend];
disp('Our line test\n');
%find interst point
p_inter = polyxpoly(PolyMatrix(:,1),PolyMatrix(:,2),line_test(:,1),line_test(:,2));
%find number of interset (row)
[numIntere,trash] = size(p_inter);
disp('Number of interest point:');
%determine in or out
if (rem(numIntere,2) == 0)
boOut = 0;
boOut = 1;
Can anyone has solution.
David Hill
David Hill on 1 Mar 2022
Change your function name to match (inOrOut). Cody will fail because it does not support the mapping toolbox which is needed for polyxpoly().
function ans = inOrOut(p,r)
Tran Tran
Tran Tran on 2 Mar 2022
So my solution cant be submited and I should find other solution which dont require mapping toolbox.

See Also