2D export in parrallel view with coordinate

Hi all,
In ruby, I try to know what is the coordinate of each angle of the exported jpg in parallele projection

		model = Sketchup.active_model
		view = model.active_view 
		file_path = model.path.gsub(".skp","_top_view.jpg")
		keys = {
		   :filename => file_path,
		   :width => 1000,
		   :height => 750,
		   :antialias => true,
		   :compression => 0.8,
		   :transparent => false
		 }
		 res = view.write_image keys

Any idea ?

Just guessing. Perhaps something like …

view = Sketchup.active_model.active_view
point = view.screen_coords(some_point_angled_object)

x = point.x
x_percent =( x / view.vp_width ).to_f
jpeg_width = 1000
x_jpeg = jpeg_width * x_percent

y = point.y
y_percent =( y / view.vp_height ).to_f
jpeg_height = 750
y_jpeg = jpeg_height * y_percent

jpeg_point = [ x_jpeg , y_jpeg ]

Thanks @DanRathbun but, how can I get a “some_point_angled_object”. I don’t see any method to have it.

That’s somewhat central to the question: you haven’t told us what you mean by that expression so we have no clue how you could find one via the API.

There is a french-english translation problem here. The believe the question is:
I want to know the coordinate of each corner of the exported jpg in parallel projection.

l’angle vs. le coin

Sorry all for my poor level of english.
@sWilliams is correct:

I want to know the coordinate of each corner of the exported jpg in parallel projection .

Won’t they be: 0,0 999,0 999,749 0,749?

@colin, thanks for your answer. but im looking at the Sketchup coordinate of this points.

Y’A-t-il de la géométrie dans les coins ? Sinon ce n’est pas possible de définir un seul point, mais un vecteur

1 Like

Perhaps …

view = Sketchup.active_model.active_view
screen_corners = [view.corner(0),view.corner(1),view.corner(3),view.corner(2)]
point_corners = screen_corners.map {|c| view.inputpoint(c.x,c.y).position }

… or …

corners = [0,1,3,2].map {|i| view.inputpoint(*view.corner(i)).position }

… or …

corners = [ 
  view.inputpoint(view.corner(0)).position, # top left
  view.inputpoint(view.corner(1)).position, # top right
  view.inputpoint(view.corner(3)).position, # bottom right
  view.inputpoint(view.corner(2)).position  # bottom left
]

Tested on this model … “Front View” scene page (parallel projection camera)
window.skp (966.8 KB)
Returns this …

[ Point3d(-12.0729, 0, 108.692), Point3d(174.671, 0, 108.692), 
  Point3d(174.671, 0, -2.78699), Point3d(-12.0729, 0, -2.78699) ]

… which are all on the XZ plane, (where the front of the “window wall” is.)

The camera eye is at …

Point3d(81.2992, -222.886, 52.9528)

If you wanted to tranlate these corner points back to the camera plane ,then …

y = view.camera.eye.y
corners.each {|corner| corner.y= y }

view.inputpoint uses inferencing - so it might snap to features such as vertices or mid-point.

To avoid that, use:

ray = view.pickray(x, y)
position, path = model.raytest(ray)

Unfortunately, you assume the solution wanted to hit something. This is untrue.

Basically the OP asks for the Geom::Point3d corners of the image plane.
(I suspect it is for some kind of pano camera export feature.)

In the example model above (if you open it) you’ll see that rays fired from the corners of the screen would not hit anything.

So, model.raytest(ray) would end up giving us an array of [nil,nil,nil,nil].

“image plane” As in Image entity?

No. Generally as in computer graphics …

1 Like

So what image plane are we talking about in this scenario?

Maybe something like this is useful.

view = Sketchup.active_model.active_view
ratio = view.vpwidth / view.vpheight.to_f
height = view.camera.height
width = height * ratio
up = view.camera.up
right = view.camera.xaxis
eye = view.camera.eye

[
  eye.offset(right, -width / 2).offset(up, height / 2),
  eye.offset(right, width / 2).offset(up, height / 2),
  eye.offset(right, width / 2).offset(up, -height / 2),
  eye.offset(right, -width / 2).offset(up, -height / 2)
]
2 Likes

Thanks all,
and thanks again @eneroth3 ! :heart_eyes: