Stop the Hollyweb! No DRM in HTML5.

【水】tyvj1523 平面几何入门

大意:给出三角形的三个顶点,求点X在其的内外还是边界上。

入门题,看程序吧。

program p1523;

type
 point=record
   x,y:double;
 end;
 vector=point;

Var
 a,b,c,x:point;
 ans:longint;

procedure readpoint(var p:point);
var
 s:string;
 code:longint;
  begin
  readln(s);
  val(copy(s,2,pos(',',s)-2),p.x,code);
  val(copy(s,pos(',',s)+1,length(s)-pos(',',s)-1),p.y,code);
  //writeln('(',p.x,',',p.y,')');
end;

function minus(a,b:point):vector;begin with minus do begin x:=a.x-b.x;y:=a.y-b.y; end; end;
function max(a,b:double):double;begin if a>b then exit(a);exit(b); end;
function min(a,b:double):double;begin if a<b then exit(a);exit(b); end;
procedure getans(P:longint);begin if ans=0 then ans:=p; end;
function cross(a,b:vector):double;begin exit(a.x*b.y-a.y*b.x); end;
function pinline(p,a,b:point):boolean;begin exit((p.x>=min(a.x,b.x)) and (p.x<=max(a.x,b.x))); end;
function equal(a,b:vector):boolean;begin exit((a.x=b.x) and (a.y=b.y)); end;

  begin
  readpoint(a);
  readpoint(b);
  readpoint(c);
  readpoint(x);
  ans:=0;
  if equal(x,a) or equal(x,b) or equal(x,c) then getans(4);
  if cross(minus(b,a),minus(x,a))=0 then
    if Pinline(x,a,b) then getans(3) else getans(2);
  if cross(minus(c,a),minus(x,a))=0 then
    if Pinline(x,a,c) then getans(3) else getans(2);
  if cross(minus(c,b),minus(x,b))=0 then
    if Pinline(x,b,c) then getans(3) else getans(2);
  if (cross(minus(b,a),minus(x,a))*cross(minus(b,a),minus(c,a))>0) and (cross(minus(c,a),minus(x,a))*cross(minus(c,a),minus(b,a))>0) and (cross(minus(c,b),minus(x,b))*cross(minus(c,b),minus(a,b))>0) then getans(1) else getans(2);
  writeln(ans);

end.

 

posted on 2013-05-07 21:03  灰天飞雁  阅读(172)  评论(0编辑  收藏  举报

填写您的邮件地址,订阅我们的精彩内容:  点击这里给我发消息

添加到收藏夹