# Converting-3D-Points-to-2D-Points

Converting 3D Points to 2D Points

# Converting 3D Points to 2D Points

Another useful function in the garden path program converts 3D points to 2D points.
AutoCAD usually works with 3D coordinates, but some entities, such as lightweight
polylines, are always meant to be 2D. The points returned by the getpoint function are 3D, so you need to create a function to convert them.

## To convert a 3D point to a 2D point

1. Enter the following at the Console window prompt:
`(defun 3dPoint-2dPoint (3dpt)(list (car 3dpt) (cadr 3dpt)))`
2. Test the function by entering the following at the Console prompt:
`(3dpoint-2dpoint (list 10 20 0))`

This works, but there is another consideration for the garden path application. Although
it often doesn’t matter whether a number is an integer or a real in LISP functions,
this isn’t the case with ActiveX functions, which you’ll use later in this lesson.
ActiveX functions require real numbers. You can easily modify the function to ensure
it returns reals instead of integers.

3. Enter the following code at the Console prompt:
```(defun 3dPoint-2dPoint (3dpt)(list (float(car 3dpt))
4. Run the function again:
`(3dpoint-2dpoint (list 10 20 0))`

Notice the return values are now reals (indicated by the decimal values).

5. Test the function again, this time using the getpoint function. Enter the following at the Console prompt:
`(setq myPoint(getpoint))`
6. Pick a point in the AutoCAD drawing area.

The getpoint function returns a 3D point.

7. Enter the following at the Console prompt:
`(3dPoint-2Dpoint myPoint)`

Note the 2D point returned.

Now add the function to the gpmain.lsp file, just as you did with Degrees-Radians. The new code should look like the following:

```;;;--------------------------------------------------------------;
;;; Function: 3dPoint-2dPoint                                   ;
;;;--------------------------------------------------------------;
;;; Description: This function takes one parameter representing a;
;;;              3D point (list of three integers or reals), and ;
;;;              converts it into a 2D point (list of two reals).;
;;;              There is no error checking on the 3D point      ;
;;;              parameter -- it is assumed to be a valid point. ;
;;;--------------------------------------------------------------;
;;; To do: Add some kind of parameter checking so that this      ;
;;;        function won't crash a program if it is passed a      ;
;;;        null value, or some other kind of data type than a    ;
;;;        3D point.                                             ;
;;;--------------------------------------------------------------;
(defun 3dPoint-2dPoint (3dpt)
)```

Note that the function heading includes a comment about some work you should do on
this function in the future. If you want to earn some extra credit, think about how
you would go about foolproofing this function so that invalid data does not make it
crash.

Hint: numberp and listp functionsâ€¦

```(listp '(1 1 0)) = T
(numberp 3.4) = T```

is called the Perspective Projection and the formula you seek is just the matrix- multiplication found here …point P with coordinates r_P = (x,y,z) and a plane with normal …. Convert 3D point to 2D point coordinate system and versa · 2 · points on a plane in 3D · 1 · Retrieve 2D co-ordinate from a 3D point on a …… I see this question is a bit old, but I decided to give an answer anyway for those who find this question by searching. The standard way to …3D points to 2D points. … getpoint function are 3D, so you need to create a function to convert them.point's x- and y-coordinate by the point's z-coordinate. Before projecting the point onto the canvas, we need to convert the point from world space to camera space. The resulting projected point is defined in image space, and is a 2D point (the z-coordinate can be discarded).2D Coordinates of a 3D Point … need more than just converting 3D points to pixel coordinates to produce a "complete" image.8 Oct 2012… It can be many way to transfer 3d world to 2d plane . I think the … I believe rotating is next step after you understand all the points to transfer one point from 3D into 2D . I would like to offer which mathematics in this conversion.3D projection is any method of mapping three-dimensional points to a two- dimensional plane. ….. This transformed point can then be projected onto the 2D plane using the formula (here, x/y is used as the projection plane; literature also may …

﻿﻿