Author Topic: xaxis from points  (Read 2390 times)

0 Members and 1 Guest are viewing this topic.

jcoon

  • Newt
  • Posts: 157
xaxis from points
« on: November 15, 2010, 01:53:34 PM »

I need help with a few items.

Thank you for your time.
John


1. if I use a point3d like points pt1 & pt2 and try to use dblRot = pt1.GetVectorTo(pt2).Angle.ToString()
I get an error in .getvecotor. Why? But when I use the same with a point2d I get the correct radians 0.785398163

Dim pt1 As Point3d = New Point2d(0, 0, 0)
Dim pt2 As Point3d = New Point2d(10, 10, 0)

Dim pt10 As Point2d = New Point2d(0, 0)
Dim pt20 As Point2d = New Point2d(10, 10)

Application.ShowAlertDialog("Angle from XAxis: " & pt10.GetVectorTo(pt20).Angle.ToString())
dblRot = pt10.GetVectorTo(pt20).Angle.ToString()

2. if I use the prompt to select two screen locations I get an error with getvector.
does the getvector only work with 2d points? Also If I try to make a 2dpoint by getting the .x.y of the screen selected points, it says that the property is read only. can you set (0)(1) (2) values  for points like in VBA?   

'' Prompt for the start point.
        pPtOpts.Message = vbLf & "Enter the start point for PT1: "
        pPtRes = acDoc.Editor.GetPoint(pPtOpts)
        Dim pt1 As Point3d = pPtRes.Value

        '' Exit if the user presses ESC or cancels the command
        If pPtRes.Status = PromptStatus.Cancel Then Exit Sub

        '' Prompt for the end point
        pPtOpts.Message = vbLf & "Enter direction for PT2 "
        pPtOpts.UseBasePoint = True
        pPtOpts.BasePoint = pt1
        pPtRes = acDoc.Editor.GetPoint(pPtOpts)

        Dim pt2 As Point3d = pPtRes.Value
       dblRot = pt1.GetVectorTo(pt2).Angle.ToString()




BillZndl

  • Guest
Re: xaxis from points
« Reply #1 on: November 15, 2010, 04:23:31 PM »
What are you casting dblRot as ?


Jeff H

  • Needs a day job
  • Posts: 6150
Re: xaxis from points
« Reply #2 on: November 15, 2010, 04:41:29 PM »
The Angle property only works with a Vector2D

The editor has a GetAngle Method for prompting

Here is a example showing the GetAngle then shows a message box with it in radians then degrees

Code: [Select]
[CommandMethod("GetAngle")]
        public void GetAngle()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptDoubleResult pdr = ed.GetAngle("Select or enter angle");
            System.Windows.Forms.MessageBox.Show(pdr.Value.ToString());
            Double degress = pdr.Value * (180 / Math.PI);
            System.Windows.Forms.MessageBox.Show(degress.ToString());
        }

jcoon

  • Newt
  • Posts: 157
Re: xaxis from points
« Reply #3 on: November 15, 2010, 06:03:55 PM »


BillZndl, Jeff H

dblRot = pt10.GetVectorTo(pt20).Angle.ToString()
I thought I was getting the angle of the selected screen points returned in radians. I was using 2d points.
I didn't know you couldn't get that angle from the point3d using the same code.
My goal was to get the xaxis from selected point3d locations.

Jeff H sample has the two selected points like I wanted but I wanted to change the prompt to something other than Specify second point. I didn't know how to do that other than add the   
pPtOpts.Message = vbLf & "Enter direction for PT2"

my goal is to select two points on screen to describe a line or polyline then draw another line at the same direction as that line described by the first & second pick points. that would be point3. Point3 is set 100 feet from point2 with the same xaxis in radians. at point3 finally I want to set two lines each 90 degrees left and right at 100 feet. If I can work thru a sample that basically draws a box some distance from the two selected screen picks at 90 degrees to the xaxis of that line. if you have links that might describe in more detail I'd be interested

I was trying to use the polarpoint to do this. that is what I used in vba to construct the same type of line work.

            Dim Point100 As Point3d = PolarPoints(pt2, (pi + dblRot), 100)
     
            Point101 = PolarPoints(Point100, (pi + dblRot), -10)
            Point102 = PolarPoints(Point100, (1.570796327 + dblRot), -100)
            Point103 = PolarPoints(Point100, (1.570796327 + dblRot), 100)
            Point104 = PolarPoints(Point101, (1.570796327 + dblRot), -100)
            Point105 = PolarPoints(Point101, (1.570796327 + dblRot), 100)

'draw polys or lines thru these points


            Dim acLine1 = New Line(Point102, Point103)

            Dim acLine2 = New Line(Point103, Point105)

            Dim acLine3 = New Line(Point105, Point104)

            Dim acLine4 = New Line(Point104, Point102)




BillZndl

  • Guest
Re: xaxis from points
« Reply #4 on: November 16, 2010, 06:22:07 AM »
Try this:

Code: [Select]
//Thanks to Tony Tanzillo


        public static Point3d PolarPoint(Point3d basepoint, double angle, double distance)
        {
            return new Point3d(basepoint.X + (distance * Math.Cos(angle)), basepoint.Y + (distance * Math.Sin(angle)), basepoint.Z);
        }

jcoon

  • Newt
  • Posts: 157
Re: xaxis from points
« Reply #5 on: November 16, 2010, 06:32:03 PM »
Guys,

That worked like a charm

john