How to select a point on a face

Dear Friends,
As you know when we want select a point from view we can use following codes.

ip.pick view, x, y
pt = ip.position

What can we do if we wish pick best point that belong to a face and If cannot find a point on face return nil? Thank you for your help in advance.

Again your question is far from sufficient detail!
My answer will be similar…

face_ip = ip.face
if face_ip 
  pt_plane = face_ip.vertices.first.position
  norm_plane = face_ip.normal
  plane = [pt_plane , norm_plane]
  projected_point = ip.position.project_to_plane(plane) 
  result = face.classify_point(projected_point )
  if result == Sketchup::Face::PointInside
    pt = projected_point 
  else
     pt = nil
  end
else
  pt = nil
end
1 Like

InputPoint objects use the inference engine.

So you need to use the InputPoint#degrees_of_freedom method to determine whether the point you are getting is constrained by the inference engine to the plane of a face.

Please let us know everything come to your mind. Always I can learn something new from your answer even cannot solve my problem.

"If you are on a face, then the degrees_of_freedom will be 2 meaning that you can only move on the plane of the face. "
Can you give me an example for it?

Some of it:

1 Like

You are nice guy!!! :laughing: :laughing:

You will learn better if you try yourself. It is not a difficult problem.