Vector parallel to two points


I’m having problems understand and figuring out how to place a dimension on an angle parallel to two points. I understand this has to do with Vector3d, but I’m not clear how to achieve it and I haven’t been able to find a solution yet.

I am attempting to draw a plan view of a circle and measure parts of it. Point A and Point B are two points on that circle. AB represents a chord section of said circle. The radius and arc length are variable. The location of A and B are both known, and are used as the start and end point of the desired dimension. What I can’t figure out is how to correctly combine the vectors to measure AB.


Hello DaveR,

Yes, of course I could draw it and you understand what I am trying to achieve. However, I’m attempting to write a program that can do that for me and save me the drawing time. It’s part of a larger project with many dimensions to draw. I’m trying to figure out how to measure the hypotenuse using Ruby. Currently I can only figure out how to place measurements using Vectors that measure the triangle as if it were a square (the X and Y vectors). I’m not clear on how to combine the X and Y vectors to measure the hypotenuse.


So…I moved your topic to right category… :wink:

Sorry. It wasn’t clear to me that you are trying to write a script to do this since it was posted in the wrong category and your original post says nothing about Ruby. I see @dezmo has kindly move it to the right category now.

Or to anyone.

1 Like

Ack! My apologies. I thought I was in the right spot, lol.


Here’s a code snippet to produce something similar to your image.

entities = Sketchup.active_model.entities
entities.add_face(, 0, 0),, 0, 0),, 1.m, 0)

entities.add_dimension_linear(, 0, 0),, 1.m, 0),, 1.5.m, 0)

The third argument to add_dimension_linear tells where to place the start of the dimension line, relative to the dimension start point.

Expanding on @ene_su’s reply, if you wanted the dimension to be parallel to the hypotenuse, pass the third argument as a vector perpendicular to that hypotenuse, such as, 0.5.m, 0)
1 Like

This is what I arrived at exactly when trying to figure this out myself. I began with almost a carbon copy of @enu_su’ s code snippet, and discovered that with a right triangle I could manipulate the vector in the manner in which @slbaumgartner has shown.

The problem is that I’m not dealing with right triangle, and I need to figure out how to find the angle parametrically.

Can the vector be expressed in degrees in any way?

Yes. Relative to what? You haven’t mentioned the third point in your figure triangle. I will call it C. Given two vectors, you can take the angle between them:

Given variables a, b, and the third point ‘c’ representing point data:

angle = a.vector_to(b).angle_between( a.vector_to(c) )     # in radians
puts angle.radians  # to convert to degrees for display

The points do not need to be a right angle triangle.

1 Like

The title for this is “Vector Parallel to two points”. What is needed is an orthogonal vector, which can be accomplished with a cross product.
You also mention:

So the edge lies on or parallel to the X-Y plane, and the Z axis is perpendicular to any edge in that plane. You don’t need the angle. Given an entity named edge:

a = edge.start.point
b = edge.end.point
vec_a_to_b = a.vector_to(b)
offset_vector = Z_AXIS.cross( vec_a_to_b )
dim = entities.add_dimension_linear a, b, offset_vector

The black edge above was drawn, but the linear dimension was assigned programmatically (and assigned to variable “edge”). The variable entities was assigned in the previous post:

offset_vector = Z_AXIS.cross( vec_a_to_b )
offset_vector.length = 2 #or whatever

just in case…


Hooray to BruceYoung!

Here is the slightly more flexible demonstration of what he has just said.

# Given the definition of a (Sketchup) circle and an arbitrary chord of that circle
# - add a linear dimension that is on the plane of the circle
# - parallel to the chord
# - and offset to the outside of the circle

model = Sketchup.active_model
ents = model.active_entities
model.start_operation('Dimension Chord', true)

  # define a circle
  radius = 10
  num_segs = 48
  centerpoint = [0, 0, 0]
  circle_normal = 0,1,0
  edges = ents.add_circle(centerpoint, circle_normal, radius, numsegs = num_segs)

  # choose a chord at random from the vertices of the circle
  i1 = rand(num_segs)
  i2 = rand(num_segs - 1 ) + 1
  i3 = (i1 + i2) % num_segs

  a = edges[i1].start.position
  b = edges[i3].start.position

  # draw the chord between the two points
  ents.add_edges([a, b])
  # Add a dimension that is offset from the chord and on the plane of the circle
  # The cross product of a normal(a vector) and an edge(a vector) yields a third vector
  # which is perpendicular to the plane defined by the first two vectors
  offset_vector = circle_normal.cross(a.vector_to(b)) 

  # scale the offset vector relative to length of the radius
  offset_vector.length = radius / 5.0
  # reverse the offset vector if it is pointing to the interior of the circle
  radius_to_a = centerpoint.vector_to(a)
  length = (radius_to_a + offset_vector).length
  if length < radius
      offset_vector =,0,0) - offset_vector
  # add the dimension
  ents.add_dimension_linear( a, b, offset_vector)


1 Like

Thank you, folks! Problem solved.